Matt
Matt

Reputation: 395

Ubuntu 17: Can't install mysqlclient

Trying to follow a Django tutorial but I cannot install mysqlclient.

The tutorial claims that I can do so with the following command:

pip install mysqlclient

but this generates this error:

Collecting mysqlclient   Using cached mysqlclient-1.3.12.tar.gz
    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-build-rrolctwh/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/tmp/pip-build-rrolctwh/mysqlclient/setup_posix.py", line 44, in get_config
        libs = mysql_config("libs_r")
      File "/tmp/pip-build-rrolctwh/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-build-rrolctwh/mysqlclient/

I have the most up-to-date pip and virtualenv installed.

I would like to be able to install mysqlclient so that I may continue with the tutorial.

Upvotes: 4

Views: 2650

Answers (4)

El Bachir
El Bachir

Reputation: 121

The following solved it for me :

You may need to install the Python 3 and MySQL development headers and libraries like so:

$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu

% sudo yum install python3-devel mysql-devel # Red Hat / CentOS

Then you can install mysqlclient via pip now:

$ pip install mysqlclient

Source : https://github.com/PyMySQL/mysqlclient#prerequisites

Upvotes: 1

Ladislav Zitka
Ladislav Zitka

Reputation: 1000

I had also similar issue on Centos 6, where there was a problem with mysql migration to maria, I had some conflicts, but finally I installed:

 yum list installed |grep MariaDB
MariaDB-client.x86_64  10.2.7-1.el6     @bull                                   
MariaDB-common.x86_64  10.2.7-1.el6     @bull                                   
MariaDB-compat.x86_64  10.2.7-1.el6     @bull                                   
MariaDB-devel.x86_64   10.2.7-1.el6     @bull                                   
MariaDB-server.x86_64  10.2.7-1.el6     @bull  

And the issue was resolved.

Upvotes: 0

maroof shittu
maroof shittu

Reputation: 2107

I was facing the same problems, but following the instructions in the Official mysqlclient documentation fixed it for me

but just to clarify I was running python 3.5 from a virtual environment and after installing the prerequisites, it all worked fine

Upvotes: 2

Arjen Dijkstra
Arjen Dijkstra

Reputation: 1549

You should also install the mysql and python development headers and libraries: https://github.com/PyMySQL/mysqlclient-python#prerequisites

Upvotes: 6

Related Questions