Saltycrane logo

SaltyCrane Blog

Notes on Python, Django, and web development on Ubuntu Linux

    

How to install MySQLdb in a virtualenv on Ubuntu Karmic

  • Install dependencies
    sudo apt-get build-dep python-mysqldb
  • Install MySQLdb with pip/virtualenv
    cd ~/lib/python-environments
    virtualenv --distribute --no-site-packages default
    pip install -E default/ MySQL-python

EnvironmentError: mysql_config not found

The first time, I did not install the dependencies and got the following error:

$ pip install -E default/ http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz/download
Downloading/unpacking http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz/download
  Downloading download (89Kb): 89Kb downloaded
  Running setup.py egg_info for package from http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz/download
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "", line 14, in 
      File "/tmp/pip-ZR_ZwM-build/setup.py", line 15, in 
        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 "", line 14, in 
  
  File "/tmp/pip-ZR_ZwM-build/setup.py", line 15, in 

    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
Storing complete log in ./pip-log.txt

19 Comments — feed icon Comments feed for this post


#1 Alvin Mites commented on 2010-04-22:

Thank you - was running into that same error using easy_install

pip install -E worked like a charm


#2 Israel commented on 2010-06-10:

What is the cause of this happening?

i recently upgraded mysql with ubuntus upgrade manager, and it seems to have broken python-mysqldb

i tried your steps above but it did not work for me.


#3 Jason Peddle commented on 2010-09-29:

How many times does this blog save my day. Answer: all of them. All of the times.


#4 semperos commented on 2010-11-10:

Thank you. Just starting out, and I've depended on two of your posts in one day to get going. Great work.


#5 Oskar Sjödin commented on 2010-11-13:

Thanks this post and the other covering virtualenv helped me out a lot.


#6 Thibault commented on 2011-04-01:

I ran into the same problem, and lost a few minutes, because the python-dev package was not installed. For the record.


#7 Gene commented on 2011-07-09:

Thanks for the sharing!!!! I suspect it was the build-dep part I was missing. My dog thanks you too, because I had to fix this before I could throw the ball for him.


#8 John Chase commented on 2011-07-26:

Thank you; I had the same error without build-dep.


#9 robertjd commented on 2011-08-30:

I believe it would be better to add the path to mysql_config to your PATH environment variable. This way you don't have to modify any files in the downloaded MySQL-python package.

I was using pip on OSX 10.7 and it could not find mysql_config, which is in /usr/local/mysql/bin/ (if you installed MySQL using the DMG installer) so I added this to PATH in my bin/activate script:

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
PATH="$PATH:/usr/local/mysql/bin/"
export PATH

You could also add some code to bin/activate that would search the system for common places that mysql_config can be found.


#10 Ori Peleg commented on 2011-11-27:

Thanks, I was stuck on this exactly.


#11 Sultan commented on 2011-12-30:

I've installed python-dev package and it worked for me


#12 uberj commented on 2012-01-05:

Thanks.


#13 method commented on 2012-02-05:

sudo apt-get install mysql-server mysql-client libmysqlclient15-dev python-dev

pip install -E mysql-python


#14 Karthic commented on 2012-04-18:

Great info. Worked like a charm!


#15 Rawgeek commented on 2012-04-21:

Thanks so much installing dependencies worked


#16 sframe commented on 2012-05-30:

I'm using pip in virtualenv on OS X (10.7) with MySQL installed via macports.

My issue was macports suffixed mysql_config as mysql_config5.

Solution for me:

sudo ln -s /opt/local/bin/mysql_config5 /opt/local/bin/mysql_config

Hope that helps anyone else in a similar situation.


#17 crw commented on 2012-10-06:

This also works on Precise Pangolin (12.04). Weird.


#18 ando commented on 2014-01-08:

pip install -E default/ MySQL-python ... no such option: -E


#19 neonigma commented on 2014-05-11:

It works! Thanks!

Post a comment

Required
Required, but not displayed
Optional

Format using Markdown. (No HTML.)
  • Code blocks: prefix each line by at least 4 spaces or 1 tab (and a blank line before and after)
  • Code span: surround with backticks
  • Blockquotes: prefix lines to be quoted with >
  • Links: <URL>
  • Links w/ description: [description](URL)
Created with Django | Hosted by Linode