Installing Django on Leopard (Mac OS 10.5)
I wrote these step-by-step instructions for my work for our new Mac desktop machines. I'm posting here as well in the case that they're useful...
MacPorts
Get MacPorts with the version 10.5 in it:
http://svn.macosforge.org/repository/macports/downloads/MacPorts-1.5.0/MacPorts-1.5.0-10.5.dmg
Install it, and follow this command line history...
First check if Macports has any updates...
$ sudo port selfupdate
Python
Install Python 2.4 with readline support. I chose Python 2.4 because it's the default in MacPorts when installed other libraries...
$ sudo port install readline
$ sudo port install python24
$ sudo port install py-readline
Now update the python symlink in your path to point to the Macports Python...
$ cd /usr/bin
$ sudo rm python # This is just a symlink, don't worry
$ sudo ln -s /opt/local/bin/python2.4 python
MySQL
Next get MySQL, the server variant, and install the default databases...
$ sudo port install mysql5 +server
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
$ sudo -u mysql /opt/local/bin/mysql_install_db5
With MySQL and Python installed you can now install the Python MySQL libraries. Note: When I did this it had an error compiling but there's a workaround below.
$ sudo port install py-mysql
If you get a compile error here's a good workaround until the bug is fixed...
$ cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py-mysql/work/MySQL-python-1.2.2/
$ sudo vim _mysql.c
Search for these lines:
#ifndef uint
#define uint unsigned int
#endif
And comment them out, like this:
/*
#ifndef uint
#define uint unsigned int
#endif
*/
Search for "uint" and find 2 lines like this:
uint port = MYSQL_PORT;
uint client_flag = 0;
And change them to this (we're just changing "uint" to "unsigned int"):
unsigned int port = MYSQL_PORT;
unsigned int client_flag = 0;
Jump back to your home directory to avoid an error when Macports cleans the build directory out from under you...
$ cd ~
Now run this again to build and install the new code...
$ sudo port install py-mysql
Subversion
Now let's continue on to install Subversion and checkout Django...
$ sudo port install subversion
Django
I keep a sandbox directory in my home directory for anything I check out...
$ mkdir ~/sandbox
$ cd ~/sandbox
$ svn co http://code.djangoproject.com/svn/django/trunk/ django_trunk
$ svn co http://code.djangoproject.com/svn/django/tags/releases/0.96.1 django-0.96
With Django checked out we need to link it into our Python path. I like to link it rather than installing it so I can run and test against multiple versions of Django just by updating the symlink.
Find where our site-packages directory is:
$ python
Python 2.4.4 (#1, Nov  9 2007, 10:35:45)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python24.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4', '/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/plat-mac', '/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/plat-mac/lib-scriptpackages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/lib-tk', '/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/lib-dynload', '/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages', '/opt/local/lib/python2.4/site-packages']
From here you can see the last path is our site-packages path. So we go there and symlink our checked-out version of Django in. By changing this symlink you can effectively test on multiple versions of Django. We'll be symlinking 0.96...
$ cd /opt/local/lib/python2.4/site-packages
$ sudo ln -s ~/sandbox/django-0.96/django django
$ sudo ln -s ~/sandbox/django-0.96/django/bin/django-admin.py /opt/local/bin/django-admin.py
I often use Textile or Markdown so we can install those as well...
$ sudo port install py-setuptools
$ sudo port install py-textile
$ sudo port install py-markdown
That's it! You're now set up for Django. Go code.
Dec 11, 2007: Updated to add symlink to django-admin.py to the path.
Feb 6, 2008: Updated to include building readline which may have caused some Python bus errors, as reported in the comments on this blog post. Building readline before Python has cleared up bus errors we were seeing on our Leopard development machines.
About this entry
Date Posted:
November 14th 2007 at 3:11:00 PM
Previous Entry:
Django Development Using git
Next Entry:
Django Week in Review, Dec 3 - Dec 9, 2007
Comments
blog comments powered by Disqus