10

I've spent several hours trying to install MySQLdb (the Python library) on Mac OS X Snow Leopard. I'm using these instructions from SO. I keep getting an error, so I've tried using MacPorts (as one of the answers to that question advises), but I continue to get the same error. Can anybody help?

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/josephmornin/.python-egg-cache/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found.  
  Did find:
    /Users/josephmornin/.python-egg-cache/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture
Community
  • 1
  • 1
Joe Mornin
  • 8,766
  • 18
  • 57
  • 82
  • Tried ActivePython? http://code.activestate.com/pypm/mysql-python/ – Sridhar Ratnakumar Apr 04 '11 at 17:51
  • possible duplicate of [How to install MySQLdb (Python data access library to MySQL) on Mac OS X?](http://stackoverflow.com/questions/1448429/how-to-install-mysqldb-python-data-access-library-to-mysql-on-mac-os-x) – mmmmmm Sep 03 '11 at 10:51

4 Answers4

56

sudo pip install mysql-python worked for me in 10.8.1.

aaronsw
  • 4,455
  • 5
  • 31
  • 27
9

Ack. I feel your pain. I spent a really long time also trying to get MySQL working with Python 2.6 on Snow Leopard using a Macbook Air and had lots of architecture problems. What ended up solving it for me, was making sure both my Python and MySQL installations were using a 32 bit architecture like my Snow Leopard was.

I wrote about my solution here, so maybe that'll help:

http://www.markliu.me/2010/jun/09/mysql-and-python-on-32-bit-snow-leopard/

Good luck...

Spike
  • 5,040
  • 5
  • 32
  • 47
  • @Spike- The link is broken again. While there is no problem with providing a link, this illustrates why the SO policy is to put the complete answer to the question on SO, and provide the link for reference or more detail. – kmarsh Mar 07 '14 at 15:05
4

try this in .bashrc or .bash_profile

PATH="/usr/local/mysql/bin:${PATH}"
export PATH
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export VERSIONER_PYTHON_PREFER_64_BIT=no
export VERSIONER_PYTHON_PREFER_32_BIT=yes
Peter Rosemann
  • 505
  • 8
  • 20
  • Running these right before doing a `pip install mysql-python` ended up working out just great for me. In my specific case I needed the 64-bit and swapped the values of the VERSIONER_PYTHON_PREFER_XX_BIT flags. – scwagner Apr 02 '12 at 03:34
1

You can also force python to run in 32bit mode:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
Adriaan
  • 187
  • 1
  • 7