MySQL-python (aka MySQLdb) on OSX Lion

Amazingly installing a new python driver for mysql became a 6 hour ordain, instead of a something that should just have taken 10 seconds.

Problem

It all started with this innocently looking line

import MySQLdb

and this cryptic error message

   import MySQLdb
  File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 19, in <module>

  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/neil/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
	/Users/neil/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so: mach-o, but wrong architecture

Solution

You may be able download & use  my binary (binaries) egg package ( MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg ) hopefully it will work out of the box; if not you may need to follow the following steps:

Roughly the following has worked for me:

export PATH=$PATH:/usr/local/mysql-5.5.20-osx10.6-x86_64/bin/

Note: depending on your version of mysql this part will be diferrent “mysql-5.5.20-osx10.6-x86_64”

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export ARCHFLAGS='-arch i386 -arch x86_64'

gcc 4.2 needs to be installed (or reinstalled since upgrading to lion messed things up)

you can do it by getting Xcode for free from the apple’s App Store

Note: that clicking install from the App Store does not actually install it; you need to run “Install Xcode” from the “Applications” directory

sudo easy_install MySQL-python

this should do the trick now

 

Note: you may want to make sure that the python version that you used to install the package is the same one as you use for running the program (that was not the case for me, since I was running EPD’s version; there is now an official version for mac for 2.7 so you might want to download it).

P.S.  I also installed a new 64-bit version of MySQL; but am not sure what that was needed.

If you are having problem with gcc the following might help as well.

 

Here is my search trail; including many excellent posts of others that gave the partial answers; in part as to provide references to the pages; and to improve query indexing:

 

 

 

Searched for mysqldb python lion 5:30pm

mysql-python installation problems (on… – stackoverflow.com 5:30pm

Searched for unable to execute gcc-4.2: No such file or directory 5:28pm

Searched for unable to execute gcc: No such file or directory mac 5:26pm

osx – How do I install Python Imaging… – stackoverflow.com 5:26pm

osx – Python build using wrong version… – stackoverflow.com 5:27pm

Searched for unable to execute gcc: No such file or directory 5:26pm

Searched for mac unable to execute gcc: No such file or directory 5:25pm

mysql-python and Snow Leopard – cd34.com 5:25pm

Searched for raise EnvironmentError(“%s not found” % (mysql_config.path,)) 5:20pm

Mechanical Girl : Installing Django with… – djangrrl.com – Viewed 2 times 5:21pm

Searched for mysqldb python mac 5:19pm

Installing Python MySQLdb 1.2.2 on Mac… – mangoorange.com 5:20pm

Installing MySQL, Python, MySQLdb on… – brambraakman.com 5:20pm

How to install MySQLdb (Python data access… – stackoverflow.com 5:20pm

Searched for python install mysql 5:16pm

MySQLdb User’s Guide – sourceforge.net 5:16pm

Searched for mysql python 5:11pm

MySQL for Python | Free Development software… – sourceforge.net 5:11pm

Searched for mysqldb python

 


Searched for EnvironmentError: mysql_config not found 6:09pm

Mechanical Girl : Installing Django with… – djangrrl.com – Viewed 2 times 6:09pm

Searched for mysqld lipo: can’t open input file: /var/tmp 6:02pm

MySQL :: Installing DBI and DBD-mysql… – mysql.com 6:02pm

python – Trouble Setting Up MySQLdb Module… – stackoverflow.com 6:02pm

Searched for osx add gcc path 5:57pm

How to move GCC in osx from xcode to… – stackoverflow.com 5:57pm

xcode – Setting GCC 4.2 as the default… – stackoverflow.com 5:57pm

Searched for osx add command path 5:54pm

Changing your PATH | Configuring Your… – peachpit.com 5:54pm

adding things to your PATH – MacRumors Forums – macrumors.com 5:55pm

Searched for add gcc lion bash 5:53pm

Lion and gcc/g++ command not found |… – cocoabuilder.com 5:53pm

Can’t install Ruby under Lion with RVM… – stackoverflow.com 5:53pm

Searched for xcode 5:46pm

Download Xcode 4 – Apple Developer – apple.com 5:46pm

Searched for lion install gcc 5:45pm

osx – Does Updating to OS X Lion Delete… – superuser.com 5:45pm

MySQL :: Using MySQL With Python – mysql.com 5:42pm

MySQL-python 1.2.3 : Python Package Index – python.org 5:42pm

Searched for mysql python binary mac 5:40pm

wrangling macs: Compiling the mysql-python… – blogspot.com 5:40pm

Searched for lion MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture 5:39pm

Python MySQL wrong architecture error… – stackoverflow.com 5:39pm
Searched for mysqldb lipo: can’t open input file: /var/tmp/ 6:34pm

python – Broken Pipe error when using… – stackoverflow.com 6:34pm

Installing python PIL in MAC OS, having… – arthurnn.com 6:37pm

Installing Django on Apple Mac OS X 10.7… – djangoapp.com 6:38pm

Searched for mysql lipo: can’t open input file: /var/tmp/ 6:34pm

Searched for mysqldb mac binaries 6:30pm

Getting MySQL work on OSX 10.7 Lion -… – stackoverflow.com – Viewed 2 times 6:31pm

Searched for ImportError: No module named MySQLdb 6:28pm

python – No module named mysqldb – Stack… – stackoverflow.com 6:28pm

Searched for add mysql_config to the path 6:22pm

python-MySQLdb [Archive] – Ubuntu Forums – ubuntuforums.org 6:23pm

Searched for osx EnvironmentError: mysql_config not found 6:20pm

EnvironmentError: mysql_config not found – southsearepublic.org 6:21pm

mysql – installing MySQLdb for Python… – stackoverflow.com 6:21pm

MySQL :: mysql_config = pure evil ? – mysql.com 6:21pm

Sakib’s Blog: In Ubuntu the error: Environmen… – blogspot.com 6:17pm

MySQL-python EnvironmentError: mysql_config… – infoentropy.com 6:17pm

Searched for mysql python easy setup 6:16pm

Easier setup for writing to MySQL on… – stackoverflow.com 6:16pm

Installing MySQL-python connector on… – opensourcehacker.com 6:16pm

Searched for mysql python easysetup 6:15pm

python – Why can’t easy_install find… – stackoverflow.com 6:15pm

Searched for mysql easysetup 6:15pm

DBD::mysql: Apple Support Communities – apple.com

 

Searched for python mysqldb ami 7:05pm

MySQLdb Python on a Amazon AMI EC2 |… – theadaptiveweb.org 7:05pm

Searched for mysql lion 7:03pm

Getting MySQL work on OSX 10.7 Lion -… – stackoverflow.com – Viewed 2 times 7:03pm

Installation of MySQL server on Apple… – djangoapp.com 7:04pm

Searched for download MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg 7:01pm

Cannot import mysql-python in crontab… – stackoverflow.com 7:01pm

Rusty Razor Blade – rustyrazorblade.com 7:01pm

A MySQLdb issue on Lion | Practical Computing… – practicalcomputing.org 7:01pm

Searched for MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg 7:00pm

django – python manage.py sql is throwing… – stackoverflow.com 7:01pm

Searched for MySQLdb python lion egg 7:00pm

Searched for pip osx 6:56pm

Installing Pip, Virtualenv & VirtualenvWrappe… – jamiecurle.com 6:57pm

Searched for pip 6:56pm

Searched for MySQL python lion 6:53pm

Searched for MySQL_python lion 6:52pm

mysql – Installing MySQLdb package for… – stackoverflow.com 6:53pm

Installing MySQLdb on MacOS Lion | Rusty… – rustyrazorblade.com 6:53pm

mysql – Python 32-bit can’t find MySQLdb… – stackoverflow.com 6:54pm

Error Importing MySQLdb – velocityreviews.com 7:00pm

Searched for python mysql 6:51pm

Searched for homebrew mysqldb 6:39pm

Getting MySQLdb For Python Working on… – wiffu.com 6:39pm
Searched for import MySQLdb No module named pkg_resources 7:51pm

MySQLdb, Python, MySQL and OS X: A match… – wordpress.com 7:52pm

Confusing, desparate MySQLdb problems…… – velocityreviews.com 7:52pm

Viewed results for from pkg_resources import load_entry_point importerror no module named pkg_resources,import my No module named pkg_resources (paused for at least 3 seconds with no click) 7:51pm

Searched for File “build/bdist.macosx-10.7-intel/egg/_mysql.py”, line 3, in __bootstrap__ImportError: No module named pkg_resources 7:51pm

Searched for unable to execute llvm-gcc-4.2 7:40pm

python – GDAL install on Mac OS X Lion… – stackoverflow.com 7:40pm

Searched for mac lion python 7:36pm

How to setup a Python environment on… – multigesture.net 7:36pm

Setup Python and Install Django on Mac… – hackercodex.com 7:36pm

python – Installing MatplotLib in mac… – stackoverflow.com 7:37pm

Searched for brew python 7:34pm

python homebrew by default – Stack Overflow – stackoverflow.com 7:34pm

Searched for MySQL-python ld: library not found for lbundle1.o 7:32pm

python – Python2.6 and Snow Leopard…. – stackoverflow.com 7:32pm

Searched for MySQL-python ld: library not found for -lbundle1.o 7:31pm

MySQLdb Frequently Asked Questions – sourceforge.net 7:32pm

Searched for MySQL-python lipo: can’t open input file: /var/tmp/ 7:29pm

http://javier.gr/2008/05/11/mysql-python-in-l… 7:29pm

Searched for MySQL-python ami 7:24pm

python – Amazon EC2 AMI pre-configured… – stackoverflow.com 7:24pm

Amazon Web Services Blog: ActivePython… – typepad.com

 

Searched for mysqldb lion error architecture 8:02pm

Searched for web history 8:00pm

Google Accounts – google.com – Viewed 11 times 8:00pm

Searched for wikihistory 8:00pm

Searched for import MySQLdb No module named pkg_resources 7:51pm

MySQLdb, Python, MySQL and OS X: A match… – wordpress.com 7:52pm

Confusing, desparate MySQLdb problems…… – velocityreviews.com 7:52pm

Viewed results for from pkg_resources import load_entry_point importerror no module named pkg_resources,import my No module named pkg_resources (paused for at least 3 seconds with no click) 7:51pm

Searched for File “build/bdist.macosx-10.7-intel/egg/_mysql.py”, line 3, in __bootstrap__ImportError: No module named pkg_resources 7:51pm

Searched for unable to execute llvm-gcc-4.2 7:40pm

python – GDAL install on Mac OS X Lion… – stackoverflow.com 7:40pm

Searched for mac lion python 7:36pm

How to setup a Python environment on… – multigesture.net 7:36pm

Setup Python and Install Django on Mac… – hackercodex.com 7:36pm

python – Installing MatplotLib in mac… – stackoverflow.com 7:37pm

Searched for brew python 7:34pm

python homebrew by default – Stack Overflow – stackoverflow.com 7:34pm

Searched for MySQL-python ld: library not found for lbundle1.o 7:32pm

python – Python2.6 and Snow Leopard…. – stackoverflow.com 7:32pm

Searched for MySQL-python ld: library not found for -lbundle1.o 7:31pm

MySQLdb Frequently Asked Questions – sourceforge.net 7:32pm

Searched for MySQL-python lipo: can’t open input file: /var/tmp/ 7:29pm

http://javier.gr/2008/05/11/mysql-python-in-l…

 

 

 

About Neil Rubens

see http://ActiveIntelligence.org
This entry was posted in Uncategorized. Bookmark the permalink.

11 Responses to MySQL-python (aka MySQLdb) on OSX Lion

  1. Michael Stone says:

    I get a complaint from easy_install that gcc-4.0 isn’t installed. Did you do something else that you may not have mentioned?

    • Michael Stone says:

      I upgraded Python to 2.7.2, and now I’m getting this error…

      /Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory

  2. Chad says:

    For those of us encountering the gcc error:
    Before doing the environment variable exports, switch to su with
    >sudo -i
    #export PATH=$PATH:/usr/local/mysql-5.5.17-osx10.6-x86_64/bin
    #export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
    #export ARCHFLAGS=’-arch i386 -arch x86_64′
    Then add one more export:
    #export CC=gcc-4.2
    #easy_install mysql-python

  3. Sean says:

    This worked. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *


*