Python - cannot install mysqlclient with pip

I was trying to intsall mysqlclinet to use following python module oin my program
 
import MySQLdb as db
 
As usual it will not work as "mysqlclinet" is not installed. So I tried to install it using pip.
 
sudo pip install mysqlclient
 
But it failed with following error.

building '_mysql' extension
i686-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG
_mysql.c:29:20: fatal error: Python.h: No such file or directory
 compilation terminated. error: command 'i686-linux-gnu-gcc' failed with exit status 1
 
I was using python version 3.7.0. I tried everything mentioned in various posts online, but nothing worked.
 
Many posts suggested using follwoing command:
 
sudo apt-get install python3-dev
 
I tried, but it said package is already present.
 
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-dev is already the newest version (3.5.1-3).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

Then I looked at the error again, it clearly says "Python.h" not found. So I checked /usr/lib/include/Python3.5 and "Python.h" was present there. However, there was no directory for  /usr/lib/include/Python3.7

So I tried following command:

sudo apt-get install python3.7-dev

And thereafter "mysqlclient" got installed as a charm.

Comments

Popular posts from this blog

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

pandas dataframe add missing date from range in a multi-dimensional structure with duplicate index

utility to extract date from text with java