Library not loaded: libmysqlclient.18.dylib

Posted: August 12th, 2011 | Author: | Filed under: MySQL, Python | 6 Comments »

Last week I upgraded to Lion from Snow Leopard. While I love the subtle touches of the new OS and even the natural (inverted) scrolling, it seriously screwed with my existing python packages and torched gcc until I installed X Code 4. I have a python script which uses the MySQLdb package. After a supposedly successful installation of MySQLdb, running my python script yielded the error:

ImportError: dlopen(/Users/alex/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/alex/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
Reason: image not found

For some reason the install pointed itself to the wrong place. Adding the following to your ~/.profile or ~/.bash_profile should fix the issue (assuming this is where you MySQL installation sits):

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

Open up a new terminal and you should be good to go.

Update! This also fixes some ruby 1.9 and rails 3 installation issues on OSX Lion. Thanks to Mauro Morales (@noiz777 for finding this!


6 Comments on “Library not loaded: libmysqlclient.18.dylib”

  1. 1 Thilo said at 4:33 am on October 3rd, 2011:

    Thanks a bunch – I was trying to install nginx and got this same error. Modifying the path like this as root solved the problem for me.

  2. 2 Falling Man Mark said at 11:58 am on October 4th, 2011:

    Also fixed an install of Rails 3.1 on OSX Snow Leopard. I’ve been tearing my hair out for hours, and this turned out to be the Final Solution – thank you for posting!

  3. 3 Andy Davidson said at 11:15 pm on January 3rd, 2012:

    Thanks, this works a treat for me as well.

  4. 4 Peter Hanley said at 5:57 pm on April 5th, 2012:

    I had this problem as well and this got me most of the way there, but I additionally had to add a symlink to get Apache to stop throwing errors:

    sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

    credit: http://stackoverflow.com/a/9334020/602581

  5. 5 Mikko said at 2:01 am on May 28th, 2012:

    Thanks. Saved my day.

  6. 6 William Notowidagdo said at 1:07 am on September 25th, 2012:

    Thanks. In my case, I add it to my ~/.bash_login file.


Leave a Reply