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!