0

I built/installed MySQL-python successfully; set DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH" in .bash_profile (OS X Lion). When I execute python from the command line and import MySQLdb, everything is fine.

But when I try to import MySQLdb in IDLE, I get the following:

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

I would like to know if there is something I could configure for IDLE to be able to look in /usr/local/mysql/lib/ to find libmysqlclient.

Installed Python/IDLE through python.org installer; no package managers.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
mstath
  • 111
  • 1
  • 3
  • 9

1 Answers1

0

You are likely launching IDLE via the IDLE.app application bundle, for example, by double-clicking on the IDLE icon. On OS X, GUI apps launched this way do not use a shell, like bash, and thus .bash_profile is not executed for them. While there are other ways to work around this, the simplest way in this case is to launch IDLE from a shell command line in a terminal window rather than from IDLE.app. Something like this should work if you used the default install options:

$ /usr/local/bin/idle3   # for idle3.x

or

$ /usr/local/bin/idle    # for idle2.x

You can also use a specific version number if you have multiple Python versions installed locally:

$ /usr/local/bin/idle3.2
Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • Another, better option is to workaround the broken `mysql` install by using `install_name_tool` to put the correct absolute path to the dylib in `_mysql.so` as described here: http://stackoverflow.com/questions/4730787/python-import-mysqldb-error-mac-10-6 Then you can dispense with having to set the environment variable at all. – Ned Deily Mar 22 '12 at 02:11