Scrawls from Preston...

Powered by Pelican.

Thu 22 October 2009

Installing MySQL Python bindings on OS X Leopard server

Installing the mysql-python package on Leopard is relatively easy if you've installed MySQL from the mysql.org distribution - but installing on Leopard Server is a bit more problematic.

The crux of the issue is that the version of MySQL that comes with Leopard Server does not include the header and library files needed for linking external libraries with. This applies to 10.5, but a similar process should work with 10.6.

If you attempt to build the MySQLdb python module you'll get errors like:

building '_mysql' extension

gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe -Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c _mysql.c -o build/temp.macosx-10.5-i386-2.5/_mysql.o -fno-omit-frame-pointer -pipe -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT

_mysql.c:36:23: error: my_config.h: No such file or directory

_mysql.c:36:23: error: my_config.h: No such file or directory

_mysql.c:38:19: error: mysql.h: No such file or directory

_mysql.c:38:19: error: mysql.h: No such file or directory

Apple has a [http://support.apple.com/kb/TA25017](technote) on the issue - and the solution is to download these separately. You can also just install a different version of mysql - but for a variety of reasons, I wanted to continue to run the installed version.

So here are the commands that will build you a working mysql python binding:

(assumes you have dev tools installed)

grab the binding library source:

http://sourceforge.net/projects/mysql-python/files/

mv path/to/MySQL-python-1.2.3c1.tar.gz /tmp

cd /tmp

tar xvzf MySQL-python-1.2.3c1.tar.gz

curl -O http://www.opensource.apple.com/other/MySQL-43.binaries.tar.gz

tar xzvf MySQL-43.binaries.tar.gz

tar xvzf MySQL-43.binaries/MySQL-43.root.tar.gz

cd usr

sudo ditto usr/include/ /usr/include/

sudo ditto usr/lib/ /usr/lib/

cd /tmp/MySQL-python-1.2.3c1

ARCHFLAGS='-arch i386 -arch x86_64'

export ARCHFLAGS

# edit site.cfg to point to point to /usr/bin/mysql_config

python setup.py build

sudo python setup.py install

To verify this worked - fire up a python console and 'import MySQLdb'


http://ptone.com/dablog