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
- How to use pip with crate.io — posted 2012-10-24
- How to install pip on Ubuntu — posted 2010-02-15
Using psycopg2 with virtualenv on Ubuntu
JauntyMaverick — posted 2009-07-31
- Notes on using pip and virtualenv with Django — posted 2009-05-06
- Installing Python 2.6 from source on Ubuntu Hardy — posted 2008-10-02
18 Comments — 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.
#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.
#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:
#13 method commented on 2012-02-05:
sudo apt-get install mysql-server mysql-client libmysqlclient15-dev python-dev
pip install -E mysql-python
#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
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.
#18 ando commented on 2014-01-08:
pip install -E default/ MySQL-python ... no such option: -E