centos下装不上mysqlclient

如果是报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
  • 1
  • 2
  • 3
  • 4

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

gcc
gcc-c++
python3-devel  (注意如果是python3安装的是python3-devel)
mariadb-devel   (centos7中叫把mysql-devle叫mariadb-devel)
libffi-devel
openssl-devel
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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

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

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

yum install mariadb-devel
  • 1

如果是报或者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
  • 1
  • 2
  • 3
  • 4
  • 5

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

pip3 install mysqlclient==2.0.3
  • 1
posted @ 2021-06-11 18:29  Οo白麒麟оΟ  阅读(387)  评论(0编辑  收藏  举报