Python 无法在centos上安装mysqlclient
我正在构建一个django应用程序,需要为其配置mysql。我正在尝试安装mysqlclient module for sql connection,这就是我正在尝试的Python 无法在centos上安装mysqlclient,python,mysql,django,Python,Mysql,Django,我正在构建一个django应用程序,需要为其配置mysql。我正在尝试安装mysqlclient module for sql connection,这就是我正在尝试的 pip install mysqlclient --no-cache-dir 它向我抛出以下错误。它在链接到gcc库时抛出错误 Collecting mysqlclient Downloading mysqlclient-1.3.12.tar.gz (89kB) 100% |####################
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/
这是链接mysql库文件的gcc默认功能吗?我已经在谷歌上搜索过了,它显示gcc需要as。所以我需要将其与某个位置进行符号链接。我正在服务器上运行mariadb 10.9,但在我的系统中没有找到任何此类文件 打开终端或使用ssh客户端登录到工作站/笔记本电脑/dev服务器。以root用户身份键入以下命令yum command:
# yum install mysql
Loaded plugins: downloadonly, fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirror.wiredtree.com
* extras: mirrors.serveraxis.net
* updates: bay.uchicago.edu
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.x86_64 0:5.1.71-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mysql x86_64 5.1.71-1.el6 base 893 k
Transaction Summary
================================================================================
Install 1 Package(s)
Total download size: 893 k
Installed size: 2.4 M
Is this ok [y/N]: y
Downloading Packages:
mysql-5.1.71-1.el6.x86_64.rpm | 893 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : mysql-5.1.71-1.el6.x86_64 1/1
Verifying : mysql-5.1.71-1.el6.x86_64 1/1
Installed:
mysql.x86_64 0:5.1.71-1.el6
Complete!
mysql客户端基本语法为:
mysql -u USER-NAME-HERE -h MYSQL-DB-SERVER-IP-ADDRESS-HERE -p DB-NAME
mysql -u nixcraft -h server1.cyberciti.biz -p salesdata
它在抱怨找不到mariadb libs。运行以下命令以找出原因:
ld -lmariadb --verbose
这应该告诉您gcc缺少什么
我猜您缺少了一些MySQL开发头。使用以下设备安装它们:
debian / ubuntu: sudo apt-get install python-dev libmysqlclient-dev
redhat / centos: sudo yum install python-devel mysql-devel
更新:它确实缺少共享库。我认为在CentOS上,这应该解决它:
sudo yum install MariaDB-devel
最后一个更新:只需使用PyMySQL-纯python,不需要标题,也不需要跳过这些障碍 在CentOS 7+10.2中解决
我也有同样的问题,我想提供我的答案。我刚刚在运行CentOS 7的2台服务器上安装了MariaDB(10.2.14-MariaDB-MariaDB服务器)
我已安装MariaDB,此软件包:
$ yum list installed | grep mariadb
MariaDB-client.x86_64 10.3.13-1.el7.centos @mariadb
MariaDB-common.x86_64 10.3.13-1.el7.centos @mariadb
MariaDB-compat.x86_64 10.3.13-1.el7.centos @mariadb
MariaDB-server.x86_64 10.3.13-1.el7.centos @mariadb
galera.x86_64 25.3.25-1.rhel7.el7.centos @mariadb
我发现问题在于mysqlclient需要mysql-devel包,这与mariadb-devel不同不要安装mariadb-devel强>
因此,要仅安装mysql-devel,您需要:
1.删除任何MariaDB devel
2.在yum中添加MySQL存储库
/usr/lib64/libmariadbclient.a
但是,他们的pkg配置会产生另一个名称:
> pkg-config --libs mariadb
-lmariadb
你最好向回购协议的维护者提出这个问题。解决方法是将libmariadbclient.A符号链接到libmariadbc.A:
sudo ln -s /usr/lib64/libmariadbclient.a /usr/lib64/libmariadb.a
这修复了安装
因此,基本上要在Python 3.6和CentOS 7中安装mysqlclient,您需要运行:
sudo yum install -y python36-devel mysql-devel gcc
sudo ln -s /usr/lib64/libmariadbclient.a /usr/lib64/libmariadb.a
pip install mysqlclient
对我来说最简单的解决方案是:
yum install python-devel mysql-devel
然后使用pip安装mysqlclient
pip install mysqlclient
我的问题是如何安装所有这些文件,而不是检查是否安装了这些文件,因为此命令给我提供了以下信息:
找不到-lzlib
我输入了错误的ld-请重试:)抱歉,但没有成功。得到此响应:设置区域设置失败,默认C包python-devel-2.7.5-58.el7.x86_64已安装,最新版本包MariaDB-devel-10.2.9-1.el7.centos.x86_64已安装,最新版本无需执行任何操作MariaDB-devel
这是我得到的响应,设置语言环境失败,默认为C包MariaDB-client-10.2.9-1.el7.centos.x86_64已安装,最新版本无需执行
将以下语言环境相关设置放入/etc/bashrc(对于所有用户,bash):export LANG=en_US.UTF-8 export LANGUAGE=en_US.UTF-8 export LC_COLLATE=C export LC_CTYPE=en_US.UTF-8然后运行:source/etc/bashrc或注销并登录。是否有什么原因不能从CentOS软件包存储库(例如,通过yum install MySQL python
)而不是通过pip安装客户端?
/usr/lib64/libmariadbclient.a
> pkg-config --libs mariadb
-lmariadb
sudo ln -s /usr/lib64/libmariadbclient.a /usr/lib64/libmariadb.a
sudo yum install -y python36-devel mysql-devel gcc
sudo ln -s /usr/lib64/libmariadbclient.a /usr/lib64/libmariadb.a
pip install mysqlclient
yum install python-devel mysql-devel
pip install mysqlclient