Mar 12, 2011

mysql for python on Mac

Assuming that you where able to install Mysql and Python Mysql package (mysql-python-1.2.3)
The following error appears when trying to  import MySQLdb:


dlopen(.../.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
  Referenced from: .../.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
  Reason: image not found


This happens because mysql client libraries are installed in standard unix locations, which are not standard for Mac...

Adding this environment variable fixes this quirk:
DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

Another possible solution which could work, was updating the Rpath in _mysql.so, but egg-tmp location is rebuilt during process restart, so it's not really an option.

This wouldn't work:
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so

No comments: