10

I have just created a virtual environment on my machine (I am running on ubuntu 18.04 LTS). I have the python version of 3.6.7 and now I want to install mysqlclient into my virtual environment.

After I do pip install mysqlclient it didn't work, instead it gave me errors saying;

Command "python.py egg_info" failed with error code 1 in /tmp/pip-install-zd21vfb3/mysqlclient/', and that the msql_config file is not found.

My setup tools are all up to date.

1
  • Looks like the system doesn't have mysql. mysql_config is a system config file relating to the local mysql server. Commented Dec 5, 2018 at 22:30

5 Answers 5

27

mysqlclient has a dependency on the mysql client & dev packages being installed. In order to fix this on ubuntu, you have to use apt-get to install a couple of mysql packages.

In your case, it looks like the missing mysql_config might be missing on your system. You can fix that by installing libmysqlclient-dev on ubuntu bionic.

0
14

In order to correctly install MySQLClient on a fresh Ubuntu 18.04 LTS you need to install each of the following:

# Replace python3.6 with which ever version of Python3 you are using
sudo apt-get install python3.6-dev 
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
sudo apt-get install libssl-dev

The last one is often missed on answers but is required now.

Only then can you install it via pip. Also make sure to update pip so you are not using version 9 if that installs into your vevn.

1
  • 1
    This answer is working perfectly in my case, the Last step is important
    – TapanHP
    Commented Aug 5, 2020 at 5:29
4

I was getting the same error when building my docker container. I tried installing the following in sequence but did not work.

sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
sudo apt-get install libssl-dev

Then this 👇 solved the problem.

sudo apt-get install default-libmysqlclient-dev
3

Check if you have already installed setuptools. After that in terminal

sudo apt-get install libmysqlclient-dev

Then(Keeping in mind to activate the virtual enviroment)

sudo pip3 install mysqlclient
0

You need to install certain prerequisite packages to install mysqlclient. As of mysqlclient==2.2.4, you need to install these packages:

sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config

You can always refer to this mysqlclient GitHub link to keep up with the prerequisites.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.