Installing MySQLdb on Mac OS X

18,213

Solution 1

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...

Solution 2

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

Solution 3

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

Solution 4

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

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
Share:
18,213

Related videos on Youtube

Joe Mornin
Author by

Joe Mornin

Updated on May 27, 2022

Comments

  • Joe Mornin
    Joe Mornin almost 2 years

    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
    
  • scwagner
    scwagner about 12 years
    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.
  • kmarsh
    kmarsh about 10 years
    @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.