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?

4
  • 1
    How'd you install mysql-python? easy_install, pip, etc.? Commented Apr 1, 2011 at 4:21
  • 3
    Just google for this. You will find 3 very thoroughly discussed questions on the very same topic on SO. Commented Apr 1, 2011 at 4:32
  • 2
    For instance: stackoverflow.com/questions/4730787/… Commented Apr 1, 2011 at 4:59
  • Try running arch -i386 python2.6 -c "import MySQLdb" ... and also try: code.activestate.com/pypm/mysql-python Commented Apr 1, 2011 at 7:58

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

6 Comments

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, 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.
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/ ?
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.
Same here!! Step 6 fixed it for me, without having to follow all the steps. I pip installed mysql-python.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.