CentOS7使用pip安装Python依赖时,遇到了错误提示:mysql_config command not found,再次记录下解决方法。

错误再现

1
bin/pip3 install -r requirements.txt 

安装依赖时,提示了如下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 Downloading https://files.pythonhosted.org/packages/3c/df/59cd2fa5e48d0804d213bdcb1acb4d08c403b61c7ff7ed4dd4a6a2deb3f7/mysqlclient-2.0.3.tar.gz (88kB)
100% |████████████████████████████████| 92kB 613kB/s
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found
mysql_config --version
mariadb_config --version
mysql_config --libs
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-lg7msz4s/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-lg7msz4s/mysqlclient/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-lg7msz4s/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-lg7msz4s/mysqlclient/

解决方案

看样子是mysql的依赖没有安装,可以使用yum安装,但搜到的都是libmysqlclient-dev,很显然木有这个包:

1
2
3
4
5
6
7
8
yum install libmysqlclient-dev
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
No package libmysqlclient-dev available.
Error: Nothing to do

实际上应该是mariadb-devel,因为centos7以及不默认安装mysql了。

1
yum install mariadb-devel

此时,即可正常安装依赖