错误:在安装mysqlclient时命令'x86_64 linux-gnu-gcc'

时间:2022-08-14 23:34:03

I installed django 1.8.5 in virtualenv and using python 3.4.3 the worked displayed the it works page when using sqlite

我在virtualenv中安装了django 1.8.5,使用了python 3.4.3,使用sqlite时显示了it works页面

I wanted to use mysql and I'm trying to install mysqlclient using

我想用mysql安装mysqlclient

pip install mysqlclient

pip安装mysqlclient

and I'm getting the following message

我得到了以下信息。

----------------------------------------
Failed building wheel for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient
Complete output from command /home/sasidhar/django/env/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-5lj39q67/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-da2_35zs-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/sasidhar/django/env/include/site/python3.4/mysqlclient:
running install
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.4/MySQLdb
running build_ext
building '_mysql' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,3,6,'final',1) -D__version__=1.3.6 -I/usr/include/mysql -I/usr/include/python3.4m -I/home/sasidhar/django/env/include/python3.4m -c _mysql.c -o build/temp.linux-x86_64-3.4/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG
_mysql.c:40:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Command "/home/sasidhar/django/env/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-5lj39q67/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-da2_35zs-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/sasidhar/django/env/include/site/python3.4/mysqlclient" failed with error code 1 in /tmp/pip-build-5lj39q67/mysqlclient

I did try installing libraries suggested in error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

我确实尝试过安装错误中建议的库:设置脚本退出错误:命令'x86_64 linux-gnu-gcc'在退出状态1时失败

and still the problem persists please help me solve this problem
Thanks guys!!

问题还在继续,请帮助我解决这个问题谢谢大家!!

3 个解决方案

#1


27  

You need to install python-dev:

您需要安装python-dev:

sudo apt-get install python-dev

And, since you are using python3:

既然你用的是python3:

sudo apt-get install python3-dev

This command should help you.

这个命令应该可以帮助您。

If you are using mac os you might try:

如果你正在使用mac os,你可以尝试:

brew update && brew rm python3 && brew install python3

You need to brew has been installed already, otherwise you can install it. It is very useful for getting packages in Mac OS. http://brew.sh/

您需要brew已经安装,否则您可以安装它。它对于在Mac OS中获取包非常有用。http://brew.sh/

#2


4  

For those using python3.5:

对于那些使用python3.5:

apt-get install python3.5-dev
wget https://bootstrap.pypa.io/get-pip.py
python3.5 get-pip.py
pip3.5 install mysqlclient

#3


0  

Tried all of the above suggestions and a few found elsewhere and nothing worked. In the end the solution was simple enough (courtesy of ignacionf on GitHub):

尝试了以上所有的建议,并在其他地方发现了一些,但没有奏效。最后,解决方案非常简单(感谢GitHub上的ignacionf):

pip install git+https://github.com/PyMySQL/mysqlclient-python.git

#1


27  

You need to install python-dev:

您需要安装python-dev:

sudo apt-get install python-dev

And, since you are using python3:

既然你用的是python3:

sudo apt-get install python3-dev

This command should help you.

这个命令应该可以帮助您。

If you are using mac os you might try:

如果你正在使用mac os,你可以尝试:

brew update && brew rm python3 && brew install python3

You need to brew has been installed already, otherwise you can install it. It is very useful for getting packages in Mac OS. http://brew.sh/

您需要brew已经安装,否则您可以安装它。它对于在Mac OS中获取包非常有用。http://brew.sh/

#2


4  

For those using python3.5:

对于那些使用python3.5:

apt-get install python3.5-dev
wget https://bootstrap.pypa.io/get-pip.py
python3.5 get-pip.py
pip3.5 install mysqlclient

#3


0  

Tried all of the above suggestions and a few found elsewhere and nothing worked. In the end the solution was simple enough (courtesy of ignacionf on GitHub):

尝试了以上所有的建议,并在其他地方发现了一些,但没有奏效。最后,解决方案非常简单(感谢GitHub上的ignacionf):

pip install git+https://github.com/PyMySQL/mysqlclient-python.git