Mac OS + MySQL-python-1.2.3: ImportError | Library not loaded | libmysqlclient.16.dylib

Attempting to get Python communicating with MySQL via MySQLdb on OS X resulted in the following error when I tried to import MySQLdb:

Traceback (most recent call last):
  File "./dbtest.py", line 3, in 
    import MySQLdb
  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in 
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in 
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/fitzsimj/.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: /Users/fitzsimj/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
  Reason: image not found

I eventually found a solution mentioned here. I added the following line to /etc/bashrc:

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

There is another solution suggested, using install_name_tool. That approach involves Ruby, which I’m not using.

About Jeff Fitzsimons

Jeff Fitzsimons is a software engineer in the California Bay Area. Technical specialties include C++, Win32, and multithreading. Personal interests include rock climbing, cycling, motorcycles, and photography.
This entry was posted in Technology. Bookmark the permalink.

6 Responses to Mac OS + MySQL-python-1.2.3: ImportError | Library not loaded | libmysqlclient.16.dylib

  1. Freddy V says:

    EXCELLENT!!! That was the last piece of the puzzle for me to get my database to begin importing!!! Thank you very much!

  2. Kamal says:

    Thanks for the tip! That was the last piece of the puzzle for me too. I’m running Mac OS 10.7.x on a 64-bit MacBook Pro and built MySQL-python-1.2.3 from source. (I also had to set ARCHFLAGS=’-arch x86_64′)

  3. Thank you so much. I ran into this trying to setup a Django environment on a OS X Lion Preview build.

  4. joyandrob says:

    Thanks so much! Just what I needed :^)

  5. Fredrik says:

    You’re my hero!

  6. Thanks! Exactly what I needed, but how on earth did you figure this out?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>