MySQL-Python on MacOSX 10.6 Snow Leopard

GCC was reporting a file not found error for stdarg.h early in the compile of MySQL-Python-1.2.3 on MacOSX 10.6 (Snow Leopard). I was staring right at the file, “/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h,” so it most certainly did exist. The problem seems to have been caused by the GCC compiler version and architecture I was using with my Python, Apache and MySQL installations.

$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
$ mysql --version
mysql Ver 14.14 Distrib 5.1.35, for apple-darwin9.5.0 (i386) using readline 5.1
$ /usr/sbin/httpd -v
Server version: Apache/2.2.17 (Unix)
$ python --version
Python 2.6.2

This was not obvious until I went to the trouble of downloading the MacOSX10.4u.sdk files and still had the same error—but I will spare you the tale of the hours I lost banging my head.

For reasons that don’t matter here, I had previously manually compiled both Apache and MySQL to use 32-bit architecture. As I understand from all the help I looked for online (this site where my issue with stdarg.h was part of the discussion was particularly helpful), all the various libraries, Python, and the GCC compiler need to be using the same architecture. I found two solutions:

MySQL-python-1.2.3 $ sudo CC=/usr/bin/gcc-4.0 python setup.py clean
MySQL-python-1.2.3 $ sudo CC=/usr/bin/gcc-4.0 python setup.py build
MySQL-python-1.2.3 $ sudo CC=/usr/bin/gcc-4.0 python setup.py install
MySQL-python-1.2.3 $ sudo ARCHFLAGS='-arch x86' python setup.py clean
MySQL-python-1.2.3 $ sudo ARCHFLAGS='-arch x86' python setup.py build
MySQL-python-1.2.3 $ sudo ARCHFLAGS='-arch x86' python setup.py install

Everything compiled with either one of these. The latter seems to me to be the better solution. After running it, I could load the library in Python with no errors:

>>> import MySQLdb

I was then able to get Django to talk with MySQL and set up a database. Yay!

Notes: For the compile to work you will also need the Python setuptools module. I installed it using easy_install, which I had evidently installed without installing the full setuptools package.