I want to run django with MySQL and Python 3. I initialized virtual environment with virtualenv --no-site-packages -p python3 ./
. Then I installed django and wheel using pip, so pip freeze gives
我想用MySQL和Python 3运行django。我使用virtualenv初始化虚拟环境--no-site-packages -p python3 ./。然后我用pip安装了django和wheel,所以pip冻结了
django==1.8.3
wheel==0.24.0
Then I tried installing mysqlclient with pip install mysqlclient
, but it ended with
然后我尝试用pip install mysqlclient安装mysqlclient,但最终以
Downloading/unpacking mysqlclient
Downloading mysqlclient-1.3.6.tar.gz (78kB): 78kB downloaded
Running setup.py (path:/tmp/pip-build-jpdlrnc8/mysqlclient/setup.py) egg_info for package mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient
building '_mysql' extension
i586-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -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/ondra/zelvovani/include/python3.4m -c _mysql.c -o build/temp.linux-i686-3.4/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DTAOCRYPT_DISABLE_X86ASM -g -DNDEBUG
error: command 'i586-linux-gnu-gcc' failed with exit status 1
Complete output from command /home/ondra/zelvovani/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-jpdlrnc8/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-fa_6nkh3-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ondra/zelvovani/include/site/python3.4:
running install
running build
running build_py
creating build
creating build/lib.linux-i686-3.4
copying _mysql_exceptions.py -> build/lib.linux-i686-3.4
creating build/lib.linux-i686-3.4/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-i686-3.4/MySQLdb
copying MySQLdb/compat.py -> build/lib.linux-i686-3.4/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-i686-3.4/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-i686-3.4/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-i686-3.4/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-i686-3.4/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-i686-3.4/MySQLdb
creating build/lib.linux-i686-3.4/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-3.4/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-i686-3.4/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-3.4/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-i686-3.4/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-3.4/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-3.4/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-3.4/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-i686-3.4
i586-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -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/ondra/zelvovani/include/python3.4m -c _mysql.c -o build/temp.linux-i686-3.4/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DTAOCRYPT_DISABLE_X86ASM -g -DNDEBUG
error: command 'i586-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /home/ondra/zelvovani/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-jpdlrnc8/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-fa_6nkh3-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ondra/zelvovani/include/site/python3.4 failed with error code 1 in /tmp/pip-build-jpdlrnc8/mysqlclient
Storing debug log for failure in /home/ondra/.pip/pip.log
I have installed libmysqlclient-dev
, python3-dev
, zlib1g-dev
(packages that were suggested in other questions here in *).
我已经安装了libmysqlclient-dev,python3-dev,zlib1g-dev(这是在*中的其他问题中提出的包)。
Do you have any ideas, what am I doing wrong?
你有什么想法,我做错了什么?
4 个解决方案
#1
9
Use pymysql and it should solve your problem.Use pip3 install pymysql
. After installing , in file directory project/project/__init__.py
write this
使用pymysql它应该解决你的问题。使用pip3安装pymysql。安装完成后,在文件目录project / project / __ init__.py中写下这个
import pymysql
pymysql.install_as_MySQLdb()
Note:- project is the name of your django project.
注意: - project是django项目的名称。
#2
3
You can try installing python3-dev
and libmysqlclient-dev
as the documentation says. I had the same problem until I noticed about I needed those packages.
您可以尝试安装python3-dev和libmysqlclient-dev,如文档所述。我有同样的问题,直到我注意到我需要这些包。
#3
1
If you're using python 3.5
or 3.6
you should be having the problem described in this issue.
如果您使用的是python 3.5或3.6,则应该遇到此问题中描述的问题。
Quoting one of the contributors to this library:
引用此库的一个贡献者:
Building MySQL-python on Windows is hard. You should build from source instead of pip install since you need to edit setup.cfg file.
在Windows上构建MySQL-python很难。您应该从源而不是pip安装构建,因为您需要编辑setup.cfg文件。
Thankfully there is an Unofficial Windows Binaries for Python Extension Packages by Christoph Gohlke (Laboratory for Fluorescence Dynamics, University of California, Irvine) and there you can download wheels (.whl
) for this library:
值得庆幸的是,Christoph Gohlke(加利福尼亚大学欧文分校的荧光动力学实验室)有一个非正式的Windows扩展软件包,你可以在这里下载这个库的*(.whl):
Download according to your system and python version installed.
根据您的系统和安装的python版本下载。
Then you just need to do (in the directory of the downloaded file):
然后你只需要做(在下载文件的目录中):
pip install mysqlclient-....whl
#4
0
Download the pre-compiled whl file for mysqlclient according to your OS from Christophe Gohlke’s Library of pre-compiled python packages for windows from the below location.
根据您的操作系统从Christophe Gohlke的预编译python包库下载mysqlclient的预编译whl文件,该软件包来自以下位置。
http://www.lfd.uci.edu/~gohlke/pythonlibs/#vlfd
Now got to directory where you downloaded that file and open command prompt there.
现在到达您下载该文件的目录并在那里打开命令提示符。
Now run below command
现在运行下面的命令
pip install xxx.whl
pip install xxx.whl
Best Luck !!
好运 !!
#1
9
Use pymysql and it should solve your problem.Use pip3 install pymysql
. After installing , in file directory project/project/__init__.py
write this
使用pymysql它应该解决你的问题。使用pip3安装pymysql。安装完成后,在文件目录project / project / __ init__.py中写下这个
import pymysql
pymysql.install_as_MySQLdb()
Note:- project is the name of your django project.
注意: - project是django项目的名称。
#2
3
You can try installing python3-dev
and libmysqlclient-dev
as the documentation says. I had the same problem until I noticed about I needed those packages.
您可以尝试安装python3-dev和libmysqlclient-dev,如文档所述。我有同样的问题,直到我注意到我需要这些包。
#3
1
If you're using python 3.5
or 3.6
you should be having the problem described in this issue.
如果您使用的是python 3.5或3.6,则应该遇到此问题中描述的问题。
Quoting one of the contributors to this library:
引用此库的一个贡献者:
Building MySQL-python on Windows is hard. You should build from source instead of pip install since you need to edit setup.cfg file.
在Windows上构建MySQL-python很难。您应该从源而不是pip安装构建,因为您需要编辑setup.cfg文件。
Thankfully there is an Unofficial Windows Binaries for Python Extension Packages by Christoph Gohlke (Laboratory for Fluorescence Dynamics, University of California, Irvine) and there you can download wheels (.whl
) for this library:
值得庆幸的是,Christoph Gohlke(加利福尼亚大学欧文分校的荧光动力学实验室)有一个非正式的Windows扩展软件包,你可以在这里下载这个库的*(.whl):
Download according to your system and python version installed.
根据您的系统和安装的python版本下载。
Then you just need to do (in the directory of the downloaded file):
然后你只需要做(在下载文件的目录中):
pip install mysqlclient-....whl
#4
0
Download the pre-compiled whl file for mysqlclient according to your OS from Christophe Gohlke’s Library of pre-compiled python packages for windows from the below location.
根据您的操作系统从Christophe Gohlke的预编译python包库下载mysqlclient的预编译whl文件,该软件包来自以下位置。
http://www.lfd.uci.edu/~gohlke/pythonlibs/#vlfd
Now got to directory where you downloaded that file and open command prompt there.
现在到达您下载该文件的目录并在那里打开命令提示符。
Now run below command
现在运行下面的命令
pip install xxx.whl
pip install xxx.whl
Best Luck !!
好运 !!