Minimal Django and Python for Mac OS X 10.4

Dave Everitt 3 Feb 2005, last updated 22-Aug-2016

STOP PRESS! ('STOP WEB'?) originally written in 2005 when - in response - Ned Deily from the Pythonmac-SIG list sent a far more absurdly simple Django install on a Vanilla 10.4 system and Greg Tuner also responded with a detailed get started with Django on 10.5, so some of this article is now only of historic value. Instead, I'd recommend James Bennet's wonderful Practical Django Projects (2nd Edition) which covers Django 1.1 (subsequent Django versions are 1.1-compatible). Now Django has taken off there are other guides out there (not all absurdly simple) and the Bitnami Django Stack, which installs a whole working environment. However, (when I don't actually have to do some work) I might still update it. After a long gap (serious family stuff) my Django use resumed in 2009 (1.2 'from trunk' and Python 2.6 at this update), so I'm finally getting to do some work with it. Which is nice. I'd also recommend James Bennett's Practical Django Projects (2nd Edition)Practical Django Projects - ignore the reviews, it's a great book and mine is well-thumbed or, if you're just beginning, Adrian Holovaty's The Definitive Guide To Django (2nd Edition)Definitive Guide to Django.

On Jeff Croft's blog entry Django for non-programmers, Mihira Jayasekera left a comment…

I am blown away by what you're doing (and are able to do) with Django. I'd love to start playing with it but I have you beat in the non-programming department. Do you know of any absurdly simple instructions for getting Django installed on Mac OS X (10.4.6)?

…that inspired me, as another beginner, to write this 'absurdly simple' guide, condensed from the official page on the Django site How to install Django (DON'T use the instructions for the SVN version of Django by mistake). So, if you want to see this, read on:

django-it-worked

Some words have a dotted underline - hover over them for more. The [why], [how] and [more] links (might someday) provide more information (but things have moved on, so probably not…). The references at the end offer further information.

Parts you might need (according to what happens) start with words in bold that begin:
If (followed by a description).

Parts you only need if something goes wrong are in boxes like this - skip over them if things go okay.

0. Will this guide be useful for you?

This covers only what's needed to try out Django to do some tutorials, using SQLite as a database (already installed in OS X). It isn't for production-level development, and I don't yet have an 'absurdly simple' guide for that yet :-). So the answer is yes only if you:

You may have read about installing Subversion or Macports, but they aren't required for this guide. If want to try Django on OS X in a development environment, you could use Apache2 and MySQL with MAMP.

Where it reads 'I can help no more', this is only because I cannot control your computer to find out what's wrong.

Whenever there's an instruction to type something into Terminal, type in the exact command shown on the separate line (copy and paste if you like), check what you've entered, then press return. When entering stuff in Terminal, check what you've entered is a golden rule.

1. Check you have Apple's Xcode Tools

Look in the root directory of your computer (not in 'Home') for a folder called 'Developer' [why], or use Command-F from the finder and search for 'Xcode'.

If XCode isn't installed, you can get the latest version from Apple's developer site (join if you need to):
http://developer.apple.com/tools/xcode/

2. Check your version of Python

In Terminal, type: python -V

(that's a minus sign and a capital V)

If the version is 2.3, download the Python 2 [why] directly from: http://www.python.org/ftp/python/2.5.1/python-2.5.1-macosx.dmg (Python 2.7.3 is here)

Double-click the disc image, then double-click the package to install it. Easy!

The installer preserves the Python 2.3 already on OS X [why] and makes Python 2.5.1 the current version on OS X, so it's called up by default. To check the new version number, in Terminal type: python -V

If this still reads 2.3, try the following (untested but based on OS X and Python users' experience). Type into Terminal: echo $PATH

if you get an error, check for files called .bash_profile, .bash_login or .profile (there should only be one [why]) by opening a new Terminal window and typing: ls -al (look towards the top of the list for files beginning with a dot.)

If one of the three named above exists, open it (e.g. if it is '.profile') by typing: open .profile the file will open in a text editor. Add the following on a new line at the bottom: export PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH"

Save the file and open a new Terminal window. Type: echo $PATH to check that the new path is being seen.

If no files with these names exist, create one by typing in Terminal: touch .bash_profile open .bash_profile then copy and add the following two lines [why]:
export PATH="/usr/local/bin:/usr/local/sbin:$PATH" export PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH"

close that Terminal window, open a new one and check the new paths appear in the readout (they'll be separated by : one after the other): echo $PATH

Now check the version of Python again: python -V

If it still reads 2.3 I can help no more.

3. Install Django 0.96

Download the latest stable version directly [more] from: http://www.djangoproject.com/download/0.96/tarball/

In Terminal, go to where your downloads are (try the Desktop) [how]. There will be a file named 'Django-0.96.tar.gz'. It's a kind of archive, and we're going to unpack it and install it.

Enter each of these in Terminal: tar xzvf Django-0.96.tar.gz cd Django-0.96 sudo python setup.py install

When all that's finished and you're still in Terminal, type: django-admin.py

You should get a screen of instructions (ignore them at this stage).

If it gives an error you may need to make 'django-admin.py' executable or add a path to your Terminal [more], so…

…to make the Django administration script executable, type the following (should all be on a single line, so copy and paste carefully) into Terminal: chmod +x /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/bin/django-admin.py

If typing django-admin.py into Terminal still fails, open your .bash_login or .profile file [how] and add the following path (all on one line) to django-admin.py: export PATH="/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/bin:$PATH"

Now try importing Django. In Terminal, type: python

You'll get the Python prompt, which looks like this: >>> Whenever you see the Python prompt, you're speaking directly to Python via the Python Interpreter. You know the interpreter's running in Terminal because the input lines start with the prompt >>>

Now after the >>> prompt, type: >>> import django

You should see a blank line and cursor (possibly blinking, depending on your Terminal settings), all is well.

If you see an error message that ends with: ImportError: No module named django, I can help no more.

Hit control-D to get out of the python shell.

4. Test SQLite

The SQLite database itself is enough only for trying out Django, and is already part of Mac OS X 10.4 (/usr/bin/sqlite3). PySQLite is embedded in Python 2.5 and allows Python to communicate with it. To test this, use the Python Interpreter - type the following into Terminal: python when you see the Python prompt: >>> type: >>> from sqlite3.test import dbapi then: >>> dbapi.test()

You'll get a line of dots - let it complete the test until you see 'OK' followed by the cursor on a blank line.

Hit control-D to get out of the python shell.

YOU'RE FINALLY READY TO START DJANGO TUTORIAL 01! (Yes, I've thought about writing an 'absurdly simple' version :-)

References

Python on the Mac:
www.python.org/download/mac/
MacPython Wiki:
wiki.python.org/moin/MacPython

Many thanks to Greg Turner and all those (Kent, Nehemiah, Joel, Chris, Hraban, Chris Barker and especially Ned) on the: Pythonmac-SIG mailing list.

Contact me or comment below if you have anything to say about this tutorial.

Comments:

Add a comment…

Comments (2000 characters/300 word limit) appear after approval. Add your email if you'd like a reply (it can be entered safely and won't be published, stored or spammed).

Name:
Email (optional):
Comment: