解决MySQLdb/_mysql.c:38:20: 致命错误:Python.h:没有那个文件或目录 #include “Python.h“报错

安装 pip3 install mysqlclient==1.4.6  报错

MySQLdb/_mysql.c:38:20: 致命错误:Python.h:没有那个文件或目录
     #include "Python.h"
                        ^
    编译中断。
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3.6 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-hjsbj52b/mysqlclient_7909e2510bf441a9bcb9bdca836d1ddf/setup.py'"'"'; __file__='"'"'/tmp/pip-install-hjsbj52b/mysqlclient_7909e2510bf441a9bcb9bdca836d1ddf/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-nqrli7sq/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6m/mysqlclient Check the logs for full command output.

重点报错:

 #include "Python.h"
                        ^
    编译中断。
    error: command 'gcc' failed with exit status 1

一般是缺少gcc python3-devel 

查看

[root@localhost mysite]# yum list python3 python3-devel
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装的软件包
python3.x86_64                                                 3.6.8-18.el7                                           @updates
可安装的软件包
python3.i686                                                   3.6.8-18.el7                                           updates
python3-devel.i686                                             3.6.8-18.el7                                           updates
python3-devel.x86_64                                           3.6.8-18.el7     

安装: yum install python3-devel gcc 

在安装pip3 install mysqlclient==1.4.6

[root@localhost mysite]# pip3 install mysqlclient==1.4.6
Looking in indexes: http://pypi.douban.com/simple/
Collecting mysqlclient==1.4.6
  Downloading http://pypi.doubanio.com/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz (85 kB)
     |████████████████████████████████| 85 kB 913 kB/s
  Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.4.6
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

你可能感兴趣的:(Linux运维,python3,python,数据库,开发语言)