解决方案:
手动下载,更改出错的代码,手动安装
解决步骤:
- 查找python下安装模块的文件夹site-packages,查看到多个文件夹,通过查看之前安装的模块确定安装位置
[root@localhost Python-3.7.4]# find / -name site-packages
/home/python/Python-3.7.4/Lib/site-packages
/usr/local/python3/lib/python3.7/site-packages
[root@localhost Python-3.7.4]# ls /usr/local/lib/python3.7/site-packages
colorlog easy_install.py pip-20.3.1.dist-info __pycache__
- 使用wget下载mysqlclient的安装包,地址:https://pypi.org/project/mysqlclient/2.0.2/#files
[root@localhost site-packages]# wget https://files.pythonhosted.org/packages/0e/68/f79de0e0fcdb041783124b825771e0ba6a3d0893b7b4c4735f130e42af47/mysqlclient-2.0.2.tar.gz
--2020-12-15 17:56:38-- https://files.pythonhosted.org/packages/0e/68/f79de0e0fcdb041783124b825771e0ba6a3d0893b7b4c4735f130e42af47/mysqlclient-2.0.2.tar.gz
正在解析主机 files.pythonhosted.org (files.pythonhosted.org)... 151.101.109.63, 2a04:4e42:36::319
正在连接 files.pythonhosted.org (files.pythonhosted.org)|151.101.109.63|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:88293 (86K) [application/x-tar]
正在保存至: “mysqlclient-2.0.2.tar.gz”100%[=================================================================================================================================================>] 88,293 372KB/s 用时 0.2s 2020-12-15 17:56:39 (372 KB/s) - 已保存 “mysqlclient-2.0.2.tar.gz” [88293/88293])
- 解压
[root@localhost site-packages]# tar -xvf mysqlclient-2.0.2.tar.gz
[root@localhost Python-3.7.4]# cd mysqlclient-2.0.2/MySQLdb/
vi _mysql.c
- 在vi界面中,输入1340n,直达第1340行,原for (unsigned int i=0; i<n; i++)修改如下,先声明,后调用,保存退出
?? - 进入mysqlclient-2.0.2目录,安装
[root@localhost mysqlclient-2.0.2]# python setup.py install
- 完成
解决方案二:
尝试降低mysqlclient的版本,即可安装成功。
pip3 install mysqlclient==2.0.1