Mary Poppins
Mary Poppins

Reputation: 79

Installing mysqlclient in Ubuntu returns error number 1

I am trying to install mysqlclient in Ubuntu, but the command returns error number 1. I tried the command

sudo apt install default-libmysqlclient-dev

which worked. However

pip install mysqlclient

does not. Can you please help me?

ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-VZPWLf/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-VZPWLf/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-2_cjSE/install-record.txt --single-version-externally-managed --compile
         cwd: /tmp/pip-install-VZPWLf/mysqlclient/
    Complete output (31 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/compat.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
    creating build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/MySQLdb
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_info=(1,4,4,'final',0) -D__version__=1.4.4 -I/usr/include/mysql -I/usr/include/python2.7 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-2.7/MySQLdb/_mysql.o
    MySQLdb/_mysql.c:38:10: 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
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-VZPWLf/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-VZPWLf/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-2_cjSE/install-record.txt --single-version-externally-managed --compile Check the logs for full command output

.

Upvotes: 2

Views: 2197

Answers (3)

girishsaraf03
girishsaraf03

Reputation: 109

Rather, try this solution. I was using Ubuntu 18.04 and found this solution to be useful for python version 3.7.5

Step 1. Install libpython3.7-dev via sudo

> sudo apt-get install libpython3.7-dev

Step 2: Install latest mysqlclient via pip

> python3 -m pip install mysqlclient==1.4.6

Upvotes: 2

Carlo Ledesma
Carlo Ledesma

Reputation: 446

This worked for me on Ubuntu + Python 3.7

sudo apt install python3.7 python3-dev libmysqlclient-dev libpython3.7-dev    
pip install mysqlclient

Reference

Upvotes: 2

Vijay Rajpurohit
Vijay Rajpurohit

Reputation: 1352

Looks like you haven't properly installed the header files and static libraries for python-dev. Use your package manager to install them system-wide.

For apt (Ubuntu, Debian...):

sudo apt-get install python-dev   # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

Upvotes: 3

Related Questions