Monday, October 29, 2007

OS X 10.5, Python, and MySQLdb

Over the weekend I upgraded to OS X 10.5 and ran into some issues with Python and MySQLdb. Bottom line is that I could not get MySQLdb (1.2.2) to compile. It had several issues that can be resolved with the following steps:

1. In the MySQLdb directory edit the _mysql.c file and comment out the following line:
#define uint unsigned int

Run the following commands from the Python MySQL directory

sudo mkdir /usr/local/mysql/lib/mysql

sudo ln -s /usr/local/mysql/lib/libmysqlclient_15.dylib /usr/local/mysql/lib/mysql/libmysqlclient_15.dylib

sudo ln -s /usr/local/mysql/lib/libmysqlclient_r.dylib /usr/local/mysql/lib/mysql/libmysqlclient_r.dylib

sudo ln -s /usr/local/mysql/lib/libmysqlclient_r.dylib /usr/local/mysql/lib/mysql/libmysqlclient_r.15.dylib


python setup.py build

python setup.py install

You might see a few warnings during the build process but they appear to be safe to ignore.

I referenced the following site to help with the initial compile error with the unsigned int. I added an additional sym-link to resolve a build error when attempting to find a library.



4 comments:

Anonymous said...

You can just edit site.cfg to change:
mysql_config = /usr/local/mysql/bin/mysql_config


Or, add mysql bin to your path, which is probably preferable!

Anonymous said...

I still get this error when I try importing MySQLdb in python .. any ideas

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

Kemal said...

Thanks dude, that worked for me... except, you need to run the install with sudo.

Anonymous said...

mysql-5.0.67-osx10.4-universal.tar.gz avoids the wrong architecture issues