3

I have been trying for a few days to fix this, looking at other questions but I can't find a question wth the same error that I am getting.

I have been attempting to follow this tutorial https://realpython.com/learn/start-django/ and get to this point:

Database settings First, install MySQL-python, which is a database connector for Python:

$ pip install MySQL-python

Everything has worked okay up to here but when I try and install MySQL-python I get the following error:

(env) Camerons-MacBook-Pro:django15_project camrail$ pip install MySQL-python
Collecting MySQL-python
  Using cached MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/
(env) Camerons-MacBook-Pro:django15_project camrail$ 

I found this answer https://opensourcehacker.com/2011/03/02/installing-mysql-python-connector-on-osx/ that says the MySQL utilities are not made available, so I followed their advice to fix it but to no avail. I have also tried installing developer tools xcode-select --install as some have suggested. I have tried reinstalling ez_setup.

Not really sure where to go from here, any help greatly appreciated.

tmthydvnprt
  • 10,398
  • 8
  • 52
  • 72
Cam Rail
  • 177
  • 1
  • 2
  • 11

7 Answers7

12

In my opinions mysql_config is missing on your system or the installer could not find it. Please Be sure mysql_config is really installed.

For instance,

  • On Debian/Ubuntu, You must install the package: sudo apt-get install libmysqlclient-dev

  • Running Mac OSX Mountain Lion, I simply ran this in terminal to fix: export PATH=$PATH:/usr/local/mysql/bin

This is the quickest fix I found.

Richard Morin
  • 121
  • 1
  • 4
3

I was also getting the same error while installing the mysql package by pip But after installing libmysqlclient-dev

  • sudo apt install libmysqlclient-dev
  • pip install mysql

Now it worked for me..

verified:

import mysql

  • did not find any error, Means got installed successfully and working properly
JON
  • 1,668
  • 2
  • 15
  • 18
1

Check your mysql configuration file using this:

mysql_config

Now you should get an output something like this:

mysql_config 
Usage: /usr/bin/mysql_config [OPTIONS]
Compiler: GNU 6.3.0
Options:
        --cflags         [-I/usr/include/mysql ]
        --cxxflags       [-I/usr/include/mysql ]
        --include        [-I/usr/include/mysql]
        --libs           [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -ldl]
        --libs_r         [-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -ldl]
        --plugindir      [/usr/lib/mysql/plugin]
        --socket         [/var/run/mysqld/mysqld.sock]
        --port           [0]
        --version        [5.7.18]
        --libmysqld-libs [-L/usr/lib/x86_64-linux-gnu -lmysqld -lpthread -lz -lm -lrt -latomic -lcrypt -ldl -laio -llz4 -lnuma]
        --variable=VAR   VAR is one of:
                pkgincludedir [/usr/include/mysql]
                pkglibdir     [/usr/lib/x86_64-linux-gnu]
                plugindir     [/usr/lib/mysql/plugin]
Ideally it should contain libmysqld-libs option. If it is not there, as it was not there in my case, you can assume that your mysql is broken.

In this case you can write this configuration to config file directly

rahulthakur319
  • 455
  • 4
  • 16
1

If you are using Windows OS download and install mysql-python directly from here .

roy
  • 6,685
  • 3
  • 26
  • 39
0

Not sure if it useful. But it help me to solve the problem.

apt-get install build-essential zlib1g zlib1g-dev zlibc libxml2 libxml2-dev
Danny Hong
  • 1,474
  • 13
  • 21
0

For completeness sake, on Debian Stretch the pkg is now called default-libmysqlclient-dev.

sudo apt-get install default-libmysqlclient-dev
orotalt
  • 19
  • 2
0

I run the following commands and it worked smooth in Ubuntu 17.10

sudo apt-get install libmysqlclient-dev
pip3 install mysqlclient
Fthi.a.Abadi
  • 324
  • 2
  • 8