Django on Leopard15 Jun 2008
I've been playing around with OS X Leopard. I've also been doing a bit of django development so I figured I would setup my favorite framework and see how the process went. At first I ran into a few stumbling blocks, and all the blogs I read on the subject were unnecessarily complicated. Here is my concise cookbook approach to getting django trunk running on Leopard with a mysql back-end.
Pre-Requisites: XCode 3.0 -- We'll need GCC to compile the python-mysql bindings. Download from apple developers site.
1) Download and install XCode, we'll need GCC to compile the python-mysql bindings
2) Download and install 32bit binaries from MySQL. Add /usr/local/mysql/bin to your PATH (.profile, or .bashrc). Install the mysql startup launch daemon (should be in same package).
3) Unpack the python-mysql package tar xvf MySQL-python-1.2.2
4) Open the _mysql.c file in your favorite text editor
5) Next look for the following two lines (MYSQL_PORT and client_flag) change the unit (definition we've just commented out) to unsigned.
uint port = MYSQL_PORT; uint client_flag = 0;
unsigned int port = MYSQL_PORT; unsigned int client_flag = 0;
7) Next use the build script to build and install the egg
python setup.py build sudo python setup.py install
8 ) Test out that the python-mysql bindings where installed correctly. Launch the terminal application, run the python interpreter and try loading the module:
If you see this error it probably means that you installed a 64bit version of mysql (or less likely a 64 bit version of the python interpreter). They both have to be compiled for the same architecture. The default python interpreter is 32bit, and that's also why I downloaded the 32bit binary from mysql.
Traceback (most recent call last): File "
", line 1, in File "build/bdist.macosx-10.5-i386/egg/MySQLdb/__init__.py", line 19, in ImportError: dynamic module does not define init function (init_mysql)
9) Checkout django-trunk from SVN. I did this in my home directory.
10) Install django into the site-packages directory.
ln -s /Users/yourabi/bin/django/django \ /Library/Python/2.5/site-packages/django
11) Fire up the python interpreter again, and try importing Django. If you see no errors you are all done.
Gotcha's 1) Error: (8, 'nodename nor servname provided, or not known') -- if you get this error after running ./manage.py runserver xxxx:xxx (with a specific IP and PORT) double check the IP address you entered is valid.
2) If you get the following error, you probably compiled the python-mysql bindings with a different architecture than the python interpreter installed. Both must be 32 or 64bit, and since the default Leopard python interpreter is 32bit you should probably just go with the 32bit MySQL binaries from mysql.com
Traceback (most recent call last):