Skip to content

Instantly share code, notes, and snippets.

@cole
Forked from narfdotpl/mysqldb.markdown
Created October 8, 2011 18:58
Show Gist options
  • Select an option

  • Save cole/1272701 to your computer and use it in GitHub Desktop.

Select an option

Save cole/1272701 to your computer and use it in GitHub Desktop.
MySQLdb, Python 2.5 and OS X 10.8

MySQLdb, Python 2.5 and OS X 10.8

I've wasted too much time trying to make MySQLdb work with Python 2.5, several times now.

Python 2.5 on OS X 10.6+ is 32=bit. Everything else is probably (depending on your system) 64-bit.

If you see the error:

    Traceback (most recent call last):
        ...
        import MySQLdb
      File "/Users/cole/Library/Python/2.5/site-packages/MySQLdb/__init__.py", line 19, in <module>
        import _mysql
    ImportError: dlopen(/Users/cole/Library/Python/2.5/site-packages/_mysql.so, 2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
      Referenced from: /Users/cole/Library/Python/2.5/site-packages/_mysql.so
      Reason: no suitable image found.  Did find:
    	/usr/local/lib/libmysqlclient.18.dylib: mach-o, but wrong architecture
    	/usr/local/lib/libmysqlclient.18.dylib: mach-o, but wrong architecture

Many people have similar problems. To fix (use Homebrew):

pip uninstall MySQL-python
brew uninstall mysql
brew install mysql --universal
pip install MySQL-python

Note that Homebrew does NOT seem to preserve the --universal flag when you upgrade. If you start to see the problem again, that might be why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment