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

时间:2015-10-24 06:28:06

标签: mysql django python-3.4

我在virtualenv中安装了django 1.8.5并使用了python 3.4.3 当使用sqlite

时,work显示了 it works 页面

我想使用mysql,我试图使用

安装mysqlclient

pip install mysqlclient

我收到以下消息

----------------------------------------
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

我尝试安装error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

中建议的库

仍然存在问题 请帮我解决这个问题 多谢你们!!

5 个答案:

答案 0 :(得分:28)

您需要安装python-dev:

sudo apt-get install python-dev

而且,因为你使用的是python3:

sudo apt-get install python3-dev

此命令可以帮助您。

如果您使用的是mac os,可以尝试:

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

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

答案 1 :(得分: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

答案 2 :(得分:3)

对于使用不同版本(例如Python 3.5、3.6或3.7)的用户,我发现this

第一部分

对于 Python 2.x ,使用:

  $ sudo apt-get install python-dev

对于 Python 2.7 ,使用:

  $ sudo apt-get install libffi-dev

对于 Python 3.x ,使用:

  $ sudo apt-get install python3-dev

对于 Python 3.4 ,使用:

  $ sudo apt-get install python3.4-dev

对于 Python 3.7 ,使用:

  $ sudo apt-get install python3.7-dev

第二部分

如果仍然不能解决问题,则others指出要安装

  $ sudo apt-get install build-essential

最后

  $ sudo apt-get install libssl-dev

但是最后两个并没有帮助我个人。以防万一,希望对您有所帮助。

答案 3 :(得分:2)

对于Ubuntu,您还需要安装build-essential

sudo apt-get install build-essential

答案 4 :(得分:0)

尝试了上述所有建议,并在其他地方找到了一些建议,但没有任何效果。最后解决方案很简单(由GitHub上的ignacionf提供):

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