2015-09-08 11 views
5

Ich möchte django mit MySQL und Python 3 ausführen. Ich initialisierte virtuelle Umgebung mit virtualenv --no-site-packages -p python3 ./. Dann installierte ich django und Rad pip verwenden, so pip Frost gibtKann nicht installiert werden mysqlclient in python3 virtualenv

django==1.8.3 
wheel==0.24.0 

Dann habe ich versucht mysqlclient mit pip install mysqlclient installieren, aber es endete mit

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 

habe ich installiert libmysqlclient-dev, python3-dev, zlib1g-dev (Pakete, die wurden in anderen Fragen hier im stackoverflow vorgeschlagen).

Haben Sie irgendwelche Ideen, was mache ich falsch?

Antwort

8

Verwenden Sie pymysql und es sollte Ihr Problem lösen.Verwenden Sie pip3 install pymysql. Nach der Installation in Dateiverzeichnis project/project/__init__.py schreiben diese

import pymysql 
pymysql.install_as_MySQLdb() 

Hinweis: - Projekt der Name Ihres django Projekt.

+0

Danke, es funktioniert. Aber ich würde gerne wissen, wie ich es lösen kann - auf der anderen Seite konnte ich mysqlclient installieren und beide Computer haben den selben debian und ich konnte keine verbundenen Pakete finden, in denen sie sich unterscheiden würden –

3

Sie können versuchen, python3-dev und libmysqlclient-dev zu installieren, wie the documentation sagt. Ich hatte das gleiche Problem, bis ich bemerkte, dass ich diese Pakete brauchte.

1

Wenn Sie Python 3.5 oder 3.6 verwenden, sollte das Problem in this issue beschrieben werden.

Zitiert einer der Autoren dieser Bibliothek:

Bauen von MySQL-Python unter Windows ist hart. Sie sollten von der Quelle anstelle von pip installieren, da Sie die Datei setup.cfg bearbeiten müssen.

Zum Glück gibt es ein inoffizielles Windows-Binaries für Python Erweiterungspakete von Christoph Gohlke (Labor für Fluoreszenzdynamik, University of California, Irvine) und dort können Sie herunterladen Räder (.whl) für diese Bibliothek:

Download entsprechend Ihrer System- und Python-Version installiert.

Dann brauchen Sie nur zu tun (im Verzeichnis der heruntergeladenen Datei):

pip install mysqlclient-....whl 
0

Laden Sie die vorkompilierte whl Datei für mysqlclient nach Ihrem O von Christophe Gohlke der Library of vorkompilierte Python-Paketen für Windows von der folgenden Position.

http://www.lfd.uci.edu/~gohlke/pythonlibs/#vlfd

muss jetzt Verzeichnis, in dem Sie die Datei und öffnen Eingabeaufforderung dort heruntergeladen.

Jetzt

pip installieren xxx unter Befehl ausführen.whl

Beste Glück !!

Verwandte Themen