我正在构建一个django应用程序,为此我需要配置mysql。我正在尝试为sql连接安装mysqlclient模块,这就是我正在尝试的
pip install mysqlclient --no-cache-dir
它向我抛出以下错误。它在链接到gcc库时抛出错误。
Collecting mysqlclient
Downloading mysqlclient-1.3.12.tar.gz (89kB)
100% |################################| 92kB 4.0MB/s
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
Complete output from command /home/admin/awx.varadev.com/awxenv/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-6m2TNP/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-WFoARo-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/admin/awx.varadev.com/awxenv/include/site/python2.7/mysqlclient:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/compat.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
creating build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
In file included from /usr/include/python2.7/pyconfig.h:6:0,
from /usr/include/python2.7/Python.h:8,
from _mysql.c:32:
/usr/include/python2.7/pyconfig-64.h:1188:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]
#define _POSIX_C_SOURCE 200112L
^
In file included from /usr/include/sys/types.h:25:0,
from /usr/include/mysql/mysql.h:38,
from _mysql.c:29:
/usr/include/features.h:168:0: note: this is the location of the previous definition
# define _POSIX_C_SOURCE 200809L
^
In file included from /usr/include/python2.7/pyconfig.h:6:0,
from /usr/include/python2.7/Python.h:8,
from _mysql.c:32:
/usr/include/python2.7/pyconfig-64.h:1210:0: warning: "_XOPEN_SOURCE" redefined [enabled by default]
#define _XOPEN_SOURCE 600
^
In file included from /usr/include/sys/types.h:25:0,
from /usr/include/mysql/mysql.h:38,
from _mysql.c:29:
/usr/include/features.h:170:0: note: this is the location of the previous definition
# define _XOPEN_SOURCE 700
^
gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64 -L/usr/lib64 -lmariadb -lpthread -lz -ldl -lm -lssl -lcrypto -lpython2.7 -o build/lib.linux-x86_64-2.7/_mysql.so
/usr/bin/ld: cannot find -lmariadb
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/home/admin/awx.varadev.com/awxenv/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-6m2TNP/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-WFoARo-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/admin/awx.varadev.com/awxenv/include/site/python2.7/mysqlclient" failed with error code 1 in /tmp/pip-build-6m2TNP/mysqlclient/
这是gcc的默认功能链接一个库文件为mysql?我已经在谷歌上搜索了这一点,它显示,gcc需要作为**.so**文件,我需要符号链接与一些位置。我正在运行mariadb 10.9在我的服务器上,我没有找到任何这样的文件在我的系统。
6条答案
按热度按时间42fyovps1#
在CentOS 7 + MariaDB 10.2中解决
我遇到了同样的问题,我想提供我的答案。我刚刚在我的2台服务器上安装了CentOS 7和MariaDB(10.2.14-MariaDB MariaDB服务器)。
我已经安装了MariaDB,这个软件包:
我发现问题是mysqlclient需要mysql-devel包,这与mariadb-devel不同。不要安装mariadb-devel!
因此,要只安装mysql-devel,您需要:
1.删除任何MariaDB设备
2.在yum中添加MySQL存储库
1.转到www.example.com并为CentOS选择RPM文件(对于我,我选择 "Red Hat Enterprise Linux 7/Oracle Linux 7(体系结构独立),RPM包"。单击 "下载"。) https://dev.mysql.com/downloads/repo/yum/ and select the RPM file for your CentOS (for me, I choose "Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package". Click "download".)
1.下载无需注册,复制底部链接 "不,谢谢,只是开始我的下载"。
1.转到您的终端并键入:
1.下载完成后,键入:
3.现在,安装mysql-devel
1.类型(这是我的版本,看你的):
4.现在,最后:mysql客户端
1.类型:
就是这样!它的工作就像一个魅力,现在我可以使用Python + Django + MariaDB/MySQL
对了,mysqlclient是Django推荐的连接器,参见:www.example.comhttps://docs.djangoproject.com/en/2.1/ref/databases/#mysql-db-api-drivers
祝你好运,再见!:-)
vptzau2j2#
我在https://github.com/r-dbi/RMySQL/issues/197上找到了这个解决方案:
MariaDB-devel-10.2.6-1.fc25.x86_64包仅包含一个名为以下名称的库:
但是,它们的pkg-config会产生另一个名称:
解决方法是将libmariadbclient. a符号链接到libmariadb.a:
基本上,要在Python 3.6和CentOS 7中安装mysqlclient,您需要运行:
vybvopom3#
它抱怨找不到mariadb库。运行以下命令以找出原因:
这应该会明确告诉您gcc缺少什么。
我猜您可能丢失了一些MySQL开发头文件。请使用以下命令安装它们:
更新:它确实缺少MariaDB共享库。我认为在CentOS上,这应该可以解决它:
最终更新:只要使用PyMySQL--纯Python,不需要头文件,也不需要跳过这些麻烦。
pu82cl6c4#
对我有效的最简单的解决方案是:
然后使用pip安装mysqlclient
nnvyjq4y5#
打开终端或使用ssh客户端登录到workstation/laptop/dev-server。以root用户身份键入以下命令yum command:
mysql客户端的基本语法是:
wlzqhblo6#
之后:
我能够安装mysql客户端:
环境:Centos 7,玛丽亚DB