Installing Python MySQL connector on MacOS X 10.5

Today I spent a couple of hours trying to get Python MySQLdb connector to work on my Mac OS X 10.5.7. After some search over the internet I found that I should download MySQLdb distribution from SourceForge and compile it locally. I followed Mango Orange’s Installing Python MySQLdb 1.2.2 on Mac OS X. The information here is an addendum as I took a slightly different approach.

Photo by Army Man Chaz

There is a long road to get stuff working

First of all, when I first installed MySQL I took the best version I could use with my computer. So, I got the 64 bit version. Aside all the problems I’ve ever had with 64-bit software, I still make the same mistake.

It turns out that Macs come with 32-bit python installed, and, obviously you cannot link 32-bit code with 64-bit code. So, to get everything working I needed to install a 32-bit version of MySQL, but …

As I’ve already compiled the code, the binaries were already generated, and dist and build directories were not deleted by python setup.py clean. As both directories were removed, compiling and installing was a breeze.

The error I was getting was the following:

Macintosh:MySQL-python-1.2.2 muanis$ python
Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
  import sys, pkg_resources, imp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "MySQLdb/__init__.py", line 19, in <module>
    import _mysql
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (init_mysql)

If you’re getting the same error message, chances are that you’ve got the same problem.

Leave a Reply