Search code examples
pythonubuntupython-3.6

Error Installing mysqlclient on Ubuntu 16.04 using pip and Python 3.6


I am getting a strange error when trying to install mysqlclient on Ubuntu 16.04 Xenial with pip + Python 3.6:

 pip install mysqlclient

Output:

 _mysql.c:40:20: fatal error: Python.h: No such file or directory
 compilation terminated.
 error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Following the installation requirements, I have tried installing the required libraries, but not luck so far.

sudo apt-get install python3-dev libmysqlclient-dev

Does someone know the workaround for this issue?


Solution

  • I found the problem, seems like for installing mysqlclient in python3.6 the library python3.6-dev is required.

    Just open a terminal and run the following command:

    sudo apt-get install python3.6-dev libmysqlclient-dev
    

    You may get the following error when trying to install the library:

    Reading state information...
    E: Unable to locate package python3.6-dev
    E: Couldn't find any package by glob 'python3.6-dev'
    E: Couldn't find any package by regex 'python3.6-dev'
    

    If that is the case, just try adding the following repository first:

    sudo add-apt-repository ppa:jonathonf/python-3.6
    sudo apt-get update
    

    After doing so, you should be able to install both python3.6 and python3.6-dev packages.