0

I have been trying for awhile now to get MySQLdb working. I am currently getting this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
  Referenced from: /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
  Reason: image not found

Anyone know what I need to do in order to correct these errors?

tnw
  • 13,521
  • 15
  • 70
  • 111
davidfx
  • 1
  • 1

1 Answers1

0

It looks like MySQLdb has compiled itself for the wrong architecture. I'm running OSX Lion x86_64 and I had to do this:

$ file $(which python) # so I can check my python is 64 bit

and 64bit MySQL

$ file $(which mysqld) # so I can check my MySQL is 64 bit too

You can verify the architecture of your current MySQLdb is 32bit:

$ file /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so

And then the only way I could get MySQLdb to work was to download the source, and compile with

$ ARCHFLAGS='-arch x86_64' python setup.py install

which forces the setup.py to build a 64 bit library (_mysql.so) rather than 32 bit. (Hat-tip - I found this so question to be helpful.

HTH, Dan

Community
  • 1
  • 1
danodonovan
  • 19,636
  • 10
  • 70
  • 78