Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-fs0wmmw4/mysqlclient/
Asked Answered
S

4

10

When I type the following command in Ubuntu 16.04

$ pip install mysqlclient

I get the following error:

`enter code here`Collecting mysqlclient
  Downloading https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz (89kB)
    100% |████████████████████████████████| 92kB 136kB/s 
    Complete output from command python setup.py egg_info:
    /bin/sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-fs0wmmw4/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-fs0wmmw4/mysqlclient/setup_posix.py", line 44, in get_config
        libs = mysql_config("libs_r")
      File "/tmp/pip-install-fs0wmmw4/mysqlclient/setup_posix.py", line 26, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    OSError: mysql_config not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-fs0wmmw4/mysqlclient/
Stromboli answered 16/4, 2018 at 16:53 Comment(0)
L
20

Try these instructions:

https://github.com/PyMySQL/mysqlclient-python

Or if you are using python 3. Go with these commands:

sudo apt-get install libmysqlclient-dev

sudo pip3 install mysqlclient

They both worked in my case.

Hope!! this helps

Lille answered 16/4, 2018 at 17:2 Comment(2)
Both executed for me too. I am using Python 3 with ubuntu 16.04. But still when I am trying to execute this with ipython notebook: db_url = { 'database': "city_details", 'drivername': 'mysql', 'username': 'root', 'password': '......', 'host': '127.0.0.1', 'query': {'charset': 'utf8'}, # the key-point setting } engine = create_engine(URL(**db_url), encoding="utf8") I am getting this error: ImportError: No module named 'MySQLdb'Stromboli
Try this once apt-get install python-mysqldbLille
S
4

I have just faced with this problem on Debian 10:

According to github (https://github.com/PyMySQL/mysqlclient) now should use this:

If you are on # Debian / Ubuntu first run:

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

If you are on # Red Hat / CentOS first run:

sudo yum install python3-devel mysql-devel

Then you can install mysqlclient:

pip install mysqlclient
Steeple answered 6/1, 2021 at 13:51 Comment(0)
S
1

After some investigations, and trying different solutions, I found out some points as below:

1- Most of the users install the Python from apt-get on Ubuntu 16.04.

2- The version which is exist on the main Ubuntu repository, is 3.5.x. The mysqlclient that you install with pip, has problem with python3s whose version are under the v3.6. So you should install Python3.6.

3- If you are on Windows, you could use a compiled version of mysqlclient as wheel file. You could find some of wheel files, here. Just download the file, and then:

pip install "path-of-wheel-file"

4- If you are using Ubuntu, as described here, install the python3.6 via these commands:

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6 python3.6-dev libmysqlclient-dev libmysqld-dev unzip

5- You should update setuptools:

python -m pip install --upgrade pip setuptools wheel

for python3.6:

python3.6 -m pip install --upgrade pip setuptools wheel

6- At the last step, you should install mysqlclient from source:

wget https://github.com/PyMySQL/mysqlclient-python/archive/master.zip
unzip master.zip
cd mysqlclient-python-master
python setup.py install

If your are using Django 1.11 LTS version, you should clone an older mysqlclient version (ex: v1.3.13):

wget https://github.com/PyMySQL/mysqlclient-python/archive/1.3.13.zip
unzip 1.3.13.zip
cd mysqlclient-python-master
python setup.py install
Sheugh answered 26/1, 2019 at 11:28 Comment(0)
C
0

Taking up this valuable comment from the most voted answer,

apt-get install python-mysqldb

solves this.

For instance, in a Dockerfile, it would look like:

RUN apt-get update
RUN apt-get install -y python-pip libmysqlclient-dev python-dev python-mysqldb
Churchgoer answered 9/12, 2021 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.