70

I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is sh: mysql_config: not found Could someone advice me on what to do?

rmicro@ubuntu:~$ pip install MySQL-python
Downloading/unpacking MySQL-python
 Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
 Running setup.py egg_info for package MySQL-python
 sh: mysql_config: not found
 Traceback (most recent call last):
 File "<string>", line 14, in <module>
 File "/home/rmicro/build/MySQL-python/setup.py", line 15, in <module>
 metadata, options = get_config()
 File "setup_posix.py", line 43, in get_config
 libs = mysql_config("libs_r")
 File "setup_posix.py", line 24, in mysql_config
 raise EnvironmentError("%s not found" % (mysql_config.path,))
 EnvironmentError: mysql_config not found
 Complete output from command python setup.py egg_info:
 sh: mysql_config: not found
Traceback (most recent call last):
 File "<string>", line 14, in <module>
 File "/home/rmicro/build/MySQL-python/setup.py", line 15, in <module>
 metadata, options = get_config()
 File "setup_posix.py", line 43, in get_config
 libs = mysql_config("libs_r")
 File "setup_posix.py", line 24, 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
asked Sep 18, 2011 at 5:57
1

8 Answers 8

160

On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward:

sudo apt-get install python-mysqldb

If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked question and answer: pip install mysql-python fails with EnvironmentError: mysql_config not found

Here is a very comprehensive guide by the developer: http://mysql-python.blogspot.no/2012/11/is-mysqldb-hard-to-install.html

To get all the prerequisites for python-mysqld to install it using pip (which you will want to do if you are using virtualenv), run this:

sudo apt-get install build-essential python-dev libmysqlclient-dev
answered Sep 18, 2011 at 13:03
Sign up to request clarification or add additional context in comments.

6 Comments

Could explain what you really meant by that?
I think he is saying that if you install python-mysqldb as a repository package, the system will handle dependency management for you, realizing that it needs to install libmysqlclient-dev too
@user618677: sudo apt-get install python-mysqldb
Thank you all, it worked. It pretty obvious that I need to learn more of Ubuntu.
@zalun as mentioned at the end of my answer if you want to use pip (in virtualenv) you have to install the prerequisites by hand.
|
15

You have 2 options, as described bellow:


Distribution package like Glaslos suggested:

# sudo apt-get install python-mysqldb

In this case you can't use virtualenv no-site-packages (default option) but must use:

# virtualenv --system-site-packages myenv

Use clean virtualenv and build your own python-mysql package.

First create virtualenv:

# virtualenv myvirtualenv
# source myvirtualenv/bin/activate

Then install build dependencies:

# sudo apt-get build-dep python-mysqldb

Now you can install python-mysql

# pip install mysql-python

NOTE Ubuntu package is python-mysql*db* , python pypi package is python-mysql (without db)

khollenbeck
16.2k18 gold badges68 silver badges102 bronze badges
answered Jul 17, 2012 at 12:44

Comments

8
yum install mysql-devel

It worked for me.

samayo
16.5k13 gold badges95 silver badges115 bronze badges
answered Sep 3, 2013 at 9:59

Comments

7

Reread the error message. It says:

sh: mysql_config: not found

If you are on Ubuntu Natty, mysql_config belongs to package libmysqlclient-dev

answered Sep 18, 2011 at 6:44

Comments

3

Python or Python3 with MySQL, you will need these. These libraries use MySQL's connector for C and Python (you need the C libraries installed as well), which overcome some of the limitations of the mysqldb libraries.

 sudo apt-get install libmysqlclient-dev
 sudo apt-get install python-mysql.connector
 sudo apt-get install python3-mysql.connector
answered Mar 23, 2016 at 0:28

Comments

1
  1. find the folder: sudo find / -name "mysql_config" (assume it's "/opt/local/lib/mysql5/bin")

  2. add it into PATH:export PATH:export PATH=/opt/local/lib/mysql5/bin:$PATH

  3. install it again

samayo
16.5k13 gold badges95 silver badges115 bronze badges
answered Dec 5, 2011 at 6:30

Comments

1

this worked for me on python 3

pip install mysqlclient

answered Jun 26, 2017 at 14:27

Comments

0

In python3 with virtualenv on a Ubuntu Bionic machine the following commands worked for me:

sudo apt install build-essential python-dev libmysqlclient-dev
sudo apt-get install libssl-dev
pip install mysqlclient
answered Mar 21, 2020 at 4:48

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.