CentOS下安装MySQL时报错
背景
在CentOS中创建django项目后,需要安装虚拟环境,结果安装到mysqlclient==1.3.12时报错,就终止安装了。然后在网上百度了一大堆,才找到可行的解决的办法。
1、报错信息如下
Collecting mysqlclient==1.3.12 (from -r requirements.txt (line 41))
Using cached https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: 未找到命令
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-s2vvlk8n/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-install-s2vvlk8n/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-install-s2vvlk8n/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-s2vvlk8n/mysqlclient/
主要的错误原因是:OSError: mysql_config not found。 mysql_config 找不到,所以导致mysqlclient安装不上。
2、 解决办法
在安装mysqlclient时,先执行如下语句
(envir_vir) [root@localhost /] # yum install mysql-devel gcc gcc-devel python-devel
如果看到有如下信息,就是执行成功了:
Running transaction
正在安装 : python-devel-2.7.5-76.el7.x86_64 1/2
正在安装 : mysql-community-devel-5.7.24-1.el7.x86_64 2/2
验证中 : mysql-community-devel-5.7.24-1.el7.x86_64 1/2
验证中 : python-devel-2.7.5-76.el7.x86_64 2/2
已安装:
mysql-community-devel.x86_64 0:5.7.24-1.el7
python-devel.x86_64 0:2.7.5-76.el7
完毕!
3、重新安装mysqlclient
在上一步安装成功后,就可以继续重新安装mysqlclient==1.3.12了
(envir_vir) [root@localhost /]# pip install mysqlclient==1.3.12
Collecting mysqlclient==1.3.12
Using cached https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz
Building wheels for collected packages: mysqlclient
Running setup.py bdist_wheel for mysqlclient ... done
Stored in directory: /root/.cache/pip/wheels/50/c7/31/81a516762c8e9324f2b1fdffc1e84b9f07224fe3707956f6e1
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.12