I downloaded and followed the install instructions for MySQL 5.5.8 (http://dev.mysql.com/downloads/mysql/) and for the MySQLdb python plugin. (http://sourceforge.net/project
In my case, I solved by adding a couple of symbolic links as in http://ageekstory.blogspot.com/2011/04/installing-massive-coupon-on-mac-os-10.html
as following:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql
You could try running otool to find out exactly what library paths the MySQLdb
C extension, _mysql.so
is looking for:
$ otool -L /Users/yanigisawa/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
and then the installed library name of the MySQL library file:
$ otool -DX /usr/local/mysql/lib/libmysqlclient.16.dylib
But you should not have to resort to setting DYLD_LIBRARY_PATH
(or using install_name_tool
to modify an executable); the need to set it is almost always a sign of a component that was built or installed incorrectly. In my experience, the MySQL project does not have a very good track record for consistency in their OS X builds and installers, as that issue you cite tends to confirm.
Trying to get a working combination of Python
, MySQLdb
, and MySQL
libraries in OS X 10.6 is a very common cause of frustration: lots of questions about it here on SO and elsewhere. There are a number reasons for that. My advice is to go with a complete solution from one of the third-party distributors that will build and install compatible versions of everything you need. And it should keep working if you need to upgrade components as time goes on. I've had good success over the years with MacPorts
; others prefer Fink
or the newer HomeBrew
. With MacPorts
, after installing the base files from the MacPorts .dmg
, you can get everything built like so:
$ sudo port selfupdate # ensure the port files are up-to-date
$ sudo port install py26-mysql
The MacPorts Python will be available at /opt/local/bin/python2.6
. If you are looking to run Django
, there's a port for that as well.
EDIT: With the updated output from otool
, you can see that there is a mismatch of library path names. The MySQLdb extension is asking for a relative path name (no initial /
), while the MySQL library advertises itself with an absolute path, normally what you want. It seems to be the reverse of the MySQL issue 59006 but, without knowing exactly what steps you've performed up until now, it is really hard to say how you got to this state. You may be able to use install_name_tool
to patch the _mysql.so
to have the absolute path name which would also eliminate any need to set DYLD_LIBRARY_PATH
. It's worth trying:
$ cd ~/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp
$ sudo install_name_tool -change libmysqlclient.16.dylib \
/usr/local/mysql/lib/libmysqlclient.16.dylib \
_mysql.so
But that should not leave you with a warm and fuzzy feeling that you can reproduce the results when you need to update something. There really is no virtue in trying to glue all these pieces from different sources into something that works.
I tried addressing the problem of an unfound dynamics library by compiling the MySQLdb module with static libraries (set static = True
in site.cfg). But that generated the same error, as _mysql.o still was asking for the dynamic library. To fix that, I added libraries = []
to the block for if static in setup_posix.py.