centos安装python mysqlclient包报mysql_config no found、Python.h no found、gcc error解决

Read Time:49 Second

如果是报OSError: mysql_config not found,则先使用yum list installed | grep xx检查如下包的安装情况。

yum list installed | grep gcc
yum list installed | grep mysql
yum list installed | grep mariadb
yum list installed | grep python

支持mysql_config是需要安装下面的软件的:

gcc
gcc-c++
python3-devel  (注意如果是python3安装的是python3-devel)
mariadb-devel   (centos7中叫把mysql-devle叫mariadb-devel)
libffi-devel
openssl-devel

即使用下面的安装语句即可

yum install gcc gcc-c++ python3-devel mariadb-devel libffi-devel openssl-devel

如果mariadb-devel安装不成功,或者还是报mysql_config not found错,则可以先通过yum list installed | grep mariadb查看所有的mariadb包,然后使用yum remove xxx把相关的包都删除,再安装mariadb-devel.

yum install mariadb-devel

如果是报或者Python.h no found错误,则检查是不是只安装了python-devel而没有安装python3-devel

如果此时还抛出gcc error,例如

MySQLdb/_mysql.c:1340:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
         for (unsigned int i=0; i<n; i++) {
         ^
    MySQLdb/_mysql.c:1340:5: note: use option -std=c99 or -std=gnu99 to compile your code
    error: command 'gcc' failed with exit status 1

上述错误是由于mysqlclient的源码编译错误,可以尝试降低mysqlclient的版本,即可安装成功。
例如:

pip3 install mysqlclient==2.0.1

转自《centos安装python mysqlclient包报mysql_config no found、Python.h no found、gcc error解决》

About Post Author

admin

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

发表评论

您的电子邮箱地址不会被公开。