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.

$ sudo port install py-mysql

Subversion (Optional)

Subversion is only needed if you want to get Django from the repository and update occasionally. See the official Django documentation on How to Install Django for other options.

Subversion comes with Leopard, and you can verify you have it on your system...

$ svn --version

If for some reason the above does not work, or you require a newer version, you can optionally install subversion via MacPorts...

$ 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/1.0 django-1.0

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 version 1.0...

$ cd /opt/local/lib/python2.4/site-packages
$ sudo ln -s ~/sandbox/django-1.0/django django
$ sudo ln -s ~/sandbox/django-1.0/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.

Updates

  • Dec 11, 2007: Added 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.
  • Oct 25, 2008: Updated to remove the py-mysql driver bug which is now fixed.
  • Oct 30, 2008: Updated to note that Subversion is optional (both in terms of installing it and in terms of getting Django installed). Also updated to svn co the 1.0 version.

About this entry

Date Posted:
November 14th 2007 at 3:11:00 PM

Tagged:
django, mac os x

Previous Entry:
Django Development Using git

Next Entry:
Django Week in Review, Dec 3 - Dec 9, 2007