错误代码如下
Collecting mysqlclient==2.2.4
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/79/33/996dc0ba3f03e2399adc91a7de1f61cb14b57ebdb4cc6eca8a78723043cb/mysqlclient-2.2.4.tar.gz (90 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [24 lines of output]
Trying pkg-config --exists mysqlclient
Command 'pkg-config --exists mysqlclient' returned non-zero exit status 1.
Trying pkg-config --exists mariadb
Command 'pkg-config --exists mariadb' returned non-zero exit status 1.
Trying pkg-config --exists libmariadb
Command 'pkg-config --exists libmariadb' returned non-zero exit status 1.
Traceback (most recent call last):
File "/www/wwwroot/PySoft/ameienv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
原因是因为
MariaDB数据库是centos操作系统中自带的,但是!!! MySQL 和 MariaDB 是不同的数据库系统,它们各自提供的开发库有文件冲突,不能同时安装。索性手动安装!
- 卸载MariaDB库
# 查看
rpm -qa | grep mariadb
mariadb-libs-1:5.5.68-1.el7.x86_64
mariadb-devel-1:5.5.68-1.el7.x86_64
#卸载
rpm -e mariadb-devel-1:5.5.68-1.el7.x86_64
rpm -e mariadb-libs-1:5.5.68-1.el7.x86_64
卸载之后,不可用yum,也不可pip安装 mysql-devel,因为yum或者pip安装mysql-devel ,会比较扯,使用yum安装的时候 ,mariadb会再次被安装
- 去官网下载对应的系统,mysql版本,安装mysql-devel
我的mysql版本,以及服务器系统,如图
可单独下载,也可下载压缩包
下载之后传到服务器上,解压
tar -xvf mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar
一定要按顺序安装,因为它们互相依赖
rpm -ivh mysql-community-common-8.0.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.24-1.el7.x86_64.rpm
如过安装过程中报错,如下图
使用强制安装
rpm -ivh mysql-community-libs-8.0.24-1.el7.x86_64.rpm --nodeps --force
查看
然后用pip安装 mysqlclient
#我用的是2.2.4版本,按需选择版本
pip install mysqlclient==2.2.4
至此解决问题!