2

I've spent what feels like forever running down MySQL blogs and SO questions trying to figure out how to install a MySQL server and MySQLdb for Python on my Mac OS 10.6.7. I think I got the MySQL server installed through MacPorts(which took an eternity), but I can't import MySQLdb (downloaded from here) with Python.

Here's the error I get:

import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/_mysql.so
Reason: image not found

I followed the instructions on this question for cleaning up and reinstalling my MySQLdb installation. Everything worked fine going through the steps, but it resulted in the same error.

I'm also not sure why it's calling the EPD64.framework directory -- the module folder and contents are actually contained in /Library/Frameworks/Python.Framework/.../site-packages. Could MacPorts have crossed the wires somewhere?

(I did one extra step of modifying the msyql_config path in site.cfg to /user/local/mysql/bin/mysql_config)

I also tried to follow the advice of this question but can't find the /User/$User/.python-eggs directory at all, so not sure what to do about that.

Any ideas?

Community
  • 1
  • 1
tchaymore
  • 3,728
  • 13
  • 55
  • 86
  • 1
    possible duplicate of [Python: MySQLdb and "Library not loaded: libmysqlclient.16.dylib"](http://stackoverflow.com/questions/4559699/python-mysqldb-and-library-not-loaded-libmysqlclient-16-dylib) – dting Apr 19 '11 at 17:00
  • Just noticed when reading over your question again, you have "/user/local/mysql/bin/mysql_config" and it should be "/usr/local/mysql..." note the spelling of the "usr" directory NOT "user" – Jordan Messina Apr 19 '11 at 17:03
  • 1
    `/Library/Frameworks/EPD64.framework/Versions/6.3` indicates you have installed and are using a Python from the Enthought Python Distribution. Since you've already installed the server from MacPorts, why don't you just install everything you need (Python, MySQLdb, MySQL client libs) from MacPorts instead of fighting all the dependencies when pulling components from disparate sources? – Ned Deily Apr 19 '11 at 17:18
  • @Jordan Messina -- thanks for pointing that out. I've double-checked and it was just an error here and not on my system. – tchaymore Apr 19 '11 at 17:20
  • @Ned Deily -- I would love to just use MacPorts but I had already installed it via the SourceForge download and thought it would screw things up. Thoughts? – tchaymore Apr 19 '11 at 17:22
  • @DTing thanks for the reference -- I think that did the trick for me. – tchaymore Apr 19 '11 at 17:23
  • `sudo port sync` and `sudo port install py25-mysql` would install a completely independent Python 2.5 and MySQLdb under the MacPorts directory structure. `/opt/local/bin/python2.5`. If you can, consider moving to a more modern Python, too. Python 2.7 is current for Python 2. Just substitute `py27` for `py25` above. – Ned Deily Apr 19 '11 at 17:49

1 Answers1

1

The second link in your question kind of contains the answer, but there is so much extra information mucked in that's unnecessary...

Simply make sure you have the following bin: /usr/local/mysql/bin/mysql_config

And then when installing MySQLdb all you need to do is change mysql_config.path in setup_posix.py to:

mysql_config.path = "/usr/local/mysql/bin/mysql_config"

Try simply doing that, don't do the symlinks they suggest or clean the eggs etc.

Jordan Messina
  • 1,511
  • 1
  • 16
  • 25