The World

[as I find it]

MySQLdb Python module quirk in OS X

I’ve just spent some time trying to get MySQLdb, a Python module for connecting to MySQL databases, running on OS X. Following the installation instructions resulted in this error when trying to import the MySQLdb module from Python:

ImportError: dlopen(/Users/richard/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient_r.15.dylib
  Referenced from: /Users/richard/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg-tmp/_mysql.so
  Reason: image not found

Pretty ugly-looking, eh? Fortunately, the fix was pretty easy; I found a solution on this page in the MySQL forums. Instead of creating a /usr/local/mysql/lib/mysql directory and copying the library into it, though, I made it a symbolic link back up to its parent. Thus, my version of the fix is just one line:

sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

Now, the MySQLdb module imports just fine!

Advertisements

Written by whereofwecannotspeak

November 2, 2007 at 11:58 pm

3 Responses

Subscribe to comments with RSS.

  1. Thanks for your post–I was having the same problem and this was the fix.

    Q

    November 23, 2007 at 1:51 pm

  2. Thanks from a fellow Leopard user. No more sqlite3 for me in django 🙂

    Jure Cuhalev

    March 20, 2008 at 5:41 pm

  3. A thousand regards!

    You saved my day/week! 🙂

    Yavar

    July 31, 2008 at 9:37 pm


Comments are closed.

%d bloggers like this: