17 Sep 2009, 12:17am
Python:
by

1 comment

Install MySQLdb for Python on Mac OS X

I don’t do much python development. I really like the language and there are a lot of great software projects out there for it. Tornado, for example, is a fast non-blocking web server in python, just open sourced by Facebook that is the engine behind FriendFeed.com.

I downloaded the source, available at, http://tornadoweb.org, and started playing around. It comes with a database wrapper for mysql. Using “easy_install”, I suppose the python equivalent to gems, it goes something like this…

sudo easy_install MySQLdb-python

Nope :( at least not on OS X. Time to do it the hard way. Luckily not too hard. It just can’t find the right path to mysql_config. Sound familiar? http://seanbehan.com/databases/install-do_mysql-ruby-gem-on-mac-os-x/

Anyway, here are the commands that worked for me…

wget http://dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3c1.tar.gz
tar xzvf MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1

In the setup_posix.py file change

mysql_config.path = "mysql_config"

to

mysql_config.path = "/opt/local/lib/mysql5/bin/mysql_config"

Next install it with these commands

 python setup.py clean
 python setup.py build
 sudo python setup.py install

That should do it.

  • Simon

    Hi Sean, this worked for me as a newbie Mac OS X user and I didn’t even need to change the setup_posix.py.

    Cheers for that

    Simon