mysql-python installation problems (on mac os x lion)

I think there might be slight quirks with doing this on Mac 64-bit (and if you google this problem shows up a lot too).

I’ve run into it, and there are a couple things you can do:

Override the environment

You can change the DYLD_LIBRARY_PATH environment variable, which tells the linker where to look for dynamic libraries (.so files and such). You said you also downloaded the 64-bit version of MySQL, so where ever it’s installed, change the path you see here:

In a shell:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

And then run python and see if you can import MySQLdb.

If that works, you can make this permanent by altering your shell profile (.bash_profile, most likely).

Use homebrew

I don’t really like mucking around with making sure MySQL and Python and all that are correct architectures and installing them separately. I run homebrew, which is a sort of package manager for Mac. If you install that, you can pretty easily take care of this issue:

  • brew install python
  • brew install mysql
  • /usr/local/share/python/easy_install mysql-python

Do note that homebrew installs into /usr/local, so you should add /usr/local/bin to your PATH, ahead of /usr/bin and /bin, otherwise you’ll get really confused why python is different.

You can add /usr/local/share/python to your PATH as well, to make it permanent.

Leave a Comment