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
Related posts
- How to install PIL on Ubuntu — posted 2010-10-27
- 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
13
Comments
—
Comments feed for this post
#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.
#13 method commented on 2012-02-05:
sudo apt-get install mysql-server mysql-client libmysqlclient15-dev python-dev
pip install -E mysql-python
Post a comment
About
I'm Eliot and this is my notepad for programming topics such as Python, Django, Ubuntu, Emacs, etc... more »
Search Blog
Tags
-
algorithms
(5)
-
aws
(9)
-
blogproject
(20)
-
c_cplusplus
(12)
-
cardstore
(8)
-
colinux
(2)
-
concurrency
(13)
-
conkeror
(2)
-
core
(2)
-
cygwin
(17)
-
datastructures
(14)
-
datetime
(4)
-
decorators
(4)
-
django
(40)
-
emacs
(22)
-
files_directories
(11)
-
git
(5)
-
hardware
(5)
-
install_setup
(8)
-
javascript
(3)
-
keyboard
(9)
-
matplotlib
(5)
-
mercurial
(4)
-
nginx
(2)
-
persistence
(5)
-
preferences
(7)
-
processes
(4)
-
pyqt
(18)
-
python
(144)
-
ratpoison
(3)
-
regexes
(6)
-
rsync
(3)
-
softwaretools
(17)
-
sql
(14)
-
ssh
(10)
-
subversion
(6)
-
twisted
(7)
-
ubuntu
(65)
-
urxvt
(5)
-
vxworks
(25)
-
webdev
(5)
-
wmii
(7)
Blogroll
- Adam Gomaa
- Alex Clemesha
- Amir Salihefendic
- Armin Ronacher
- David Beazley
- David Ziegler
- Duncan McGreggor
- Gareth Rushgrave
- Glyph Lefkowitz
- Guido van Rossum
- Ian Bicking
- Jacob Kaplan-Moss
- James Bennett
- James Tauber
- Jesper Noehr
- Marty Alchin
- Matt Harrison
- Nikolay Kolev
- Parand Darugar
- Peter Baumgartner
- Peter Bengtsson
- Rob Hudson
- Simon Willison
- Will McGugan
#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