Dienstag, 16. Dezember 2008

Django, Python 2.6 and MySqlDb on OSX 10.5 64 bit

I've been trying to install Django on my OSX 10.5 64bit machine and it turns out super easy with the native OSX python interpreter. Unfortunately my mysql is a 64bit version and the native python is only 32bit. Not a big issue one would think, but building the MySqlDb module fails as both have to be compiled for the same architecture. So I finally ended up compiling python 2.6.1, Django 1.0.2 and MySqlDb 1.2.2 on OS X 10.5.5. And it wasn't too bad.


Python 2.6.1

Basically following this article the only thing you need to do is to pass additional build paramters to use the 64bit architecture. By default python installs into /usr/local:


$ ./configure --disable-toolbox-glue OPT="-fast -arch x86_64 -fPIC -pipe" LDFLAGS="-arch x86_64"
$ make
$ make install

For further python installation you need setuptools which can be downloaded here. All you need to do is download the python egg and run:
sh setuptools-0.6c9-py2.4.egg


Django 1.0.2

Simply running python setup.py install from the source folder did the trick. No problems here. Just make sure you use the new python2.6 interpreter and not the native python2.5 32bit one which gets called if you just run python in the terminal.

$ sudo python2.6 setup.py install


MySqlDb 1.2.2


Here it gets a bit trickier as you have to slightly modify the c header. But there are several articles around that work. You have to edit _mysql.c using your favourite text-editor. Remove the following lines (37-39):

#ifndef uint
#define uint unsigned int
#endif


Then change the following:

uint port = MYSQL_PORT;
uint client_flag = 0;

to

unsigned int port = MYSQL_PORT;
unsigned int client_flag = 0;



Create a symbolic link under lib to point to a sub-directory called mysql. This is where it looks for during compilation.

$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql



Then install the package and you are done.

$ sudo python setup.py install