一、描述
在centos7.5中执行pip3 install mysqlclient,报如下错误
[root@VM_0_10_centos data]# pip3 install mysqlclient
WARNING: Running pip install with root privileges is generally not a good idea. Try pip3 install --user
instead.
Collecting mysqlclient
Downloading http://mirrors.tencentyun.com/pypi/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz (85kB)
100% |████████████████████████████████| 92kB 793kB/s
Building wheels for collected packages: mysqlclient
Running setup.py bdist_wheel for mysqlclient … error
Complete output from command /usr/bin/python -u -c “import setuptools, tokenize;file=’/tmp/pip-build-dpijq2lm/mysqlclient/setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” bdist_wheel -d /tmp/tmp18kw5i1zpip-wheel- --python-tag cp36:
…
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,4,6,‘final’,0) -D__version__=1.4.6 -I/usr/include/mysql -I/usr/include/python3.6m -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.6/MySQLdb/_mysql.o
MySQLdb/_mysql.c:38:20: fatal error: Python.h: No such file or directory
#include “Python.h”
^
compilation terminated.
error: command ‘gcc’ failed with exit status 1
二、解决方法
For apt (Ubuntu, Debian…):
sudo apt-get install python-dev # for python2.x installs
sudo apt-get install python3-dev # for python3.x installs
For yum (CentOS, RHEL…):
sudo yum install python-devel # for python2.x installs
sudo yum install python3-devel # for python3.x installs
For dnf (Fedora…):
sudo dnf install python2-devel # for python2.x installs
sudo dnf install python3-devel # for python3.x installs
For zypper (openSUSE…):
sudo zypper in python-devel # for python2.x installs
sudo zypper in python3-devel # for python3.x installs
For apk (Alpine…):
#This is a departure from the normal Alpine naming
#scheme, which uses py2- and py3- prefixes
sudo apk add python2-dev # for python2.x installs
sudo apk add python3-dev # for python3.x installs
For apt-cyg (Cygwin…):
apt-cyg install python-devel # for python2.x installs
apt-cyg install python3-devel # for python3.x installs