2

Possible Duplicate:
Python import MySQLdb error - Mac 10.6

I've tried everything I can find online. I've installed mysql using the dmg and I've tried installing the mysql-python (which I think worked). But I still get the error when I run in the python interpreter "import MySQLdb":

>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>

  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/matthew/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/matthew/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
  Reason: image not found

I can't figure out the problem. Ideas on how to track this down?

Community
  • 1
  • 1
Matthew
  • 15,282
  • 27
  • 88
  • 123

1 Answers1

10

I've just installed this on my system and these are the steps I did to make it working:

  1. Download Mysql-python: http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.2/ (I've used 1.2.2 version)
  2. Extract, go there and edit _mysql.c file by removing 37-19 lines (ifdefine)
  3. In site.cfg set mysql_config = /usr/local/mysql/bin/mysql_config
  4. sudo python setup.py build (this one I ran two times, while the first one spitted something weird, second time went without errors... I read about this and this is weird stuff)
  5. sudo python setup.py install
  6. sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
  7. sudo ln -s /usr/local/mysql/lib/ /usr/local/mysql/lib/mysql

And finally you just try import MySQLdb in python. Hope that worked also for you.

Ignas

Ignas Butėnas
  • 6,061
  • 5
  • 32
  • 47
  • 2
    Warning! On OS X, in general you should *never* add, modify, or delete files in /usr/lib or anywhere else in `/usr` other than `/usr/local`. That space is considered part of OS X and is managed by Apple. You risk having your stuff break the next time Apple releases an update and, in the worst case, you can break your system. Same goes for `/System/Library`. – Ned Deily Apr 01 '11 at 07:08
  • Ned, I read this also... But I lived one year with installation like this and installed all the updates from Apple... Nothing was broken and nothing changed after updates. Maybe it is not best practice, but MySQL by default installs itself to /usr/local/mysql... /System/Library is really bad place for modifications, that's true! Nice tip, btw. – Ignas Butėnas Apr 01 '11 at 07:13
  • Ahh.. misunderstood your tip a little... Yes, you're about symlink in /usr/lib. Yes, this one I don't like... But this was a workaround. Maybe better is to export variable in environment then: export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ ? – Ignas Butėnas Apr 01 '11 at 07:20
  • Installing to `/usr/local/mysql` is fine. But there should be no reason you need to create a symlink to that in `/usr/lib/`. `/usr/local/lib`, perhaps. Ideally, `mysql-python` or anything else that depends on the MySQL client libraries will look in the right places. Otherwise, it should be a matter of supplying the right configuration parameters to its build. – Ned Deily Apr 01 '11 at 07:21
  • Same here!! Step 6 fixed it for me, without having to follow all the steps. I pip installed mysql-python. – Bach Apr 05 '11 at 03:42
  • Just step 6 required for me – conorgriffin Mar 24 '13 at 03:10