Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to install mysqlclient in python3 virtualenv

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

django==1.8.3
wheel==0.24.0

Then I tried installing mysqlclient with pip install mysqlclient, but it ended with

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 stackoverflow).

Do you have any ideas, what am I doing wrong?

like image 633
Ondra Mička Avatar asked Sep 08 '15 19:09

Ondra Mička


1 Answers

Use pymysql and it should solve your problem.Use pip3 install pymysql. After installing , in file directory project/project/__init__.py write this

import pymysql 
pymysql.install_as_MySQLdb()

Note:- project is the name of your django project.

like image 64
Vikas Malviya Avatar answered Sep 30 '22 00:09

Vikas Malviya