Check out the Latest Articles:
How to install Django on Mac OS X 10.6 Snow Leopard

So you got your brand spanking new Snow Leopard installed and now you want to do some Django development work on it, huh? Well, you’re in luck, because I’ve compiled this little tutorial for you.

This blog post is partly based on Rob Hudson’s Installing Django on Leopard post, which has helped me a lot in the past. Thanks, Rob!

Also, if you need help installing other tools on your machine, Dan Benjamin of hivelogic.com has created tutorials for installing MySQL, Git and Mercurial.

Prerequisites

Luckily, Snow Leopard brings everything with it that you need: Subversion and Python 2.6 are already pre-installed with the new OSX. This is especially important because as of now, 3 days after the release of OS X 10.6, there is no working version of Macports yet, which might otherwise help you install lots of command-line-tools for your mac.

Downloading Django

First, open your Terminal.app. It should be in the Utilities folder, located inside the Applications folder.

To download Django 1.1 using Subversion, first cd into the Python site-packages directory by pasting the following line into the terminal window and pressing enter:

cd /usr/local/lib/python2.6/site-packages

A few commentators rightfully point out that the correct path to the site-packages should be:

cd /Library/Python/2.6/site-packages/

And then download Django into the site packages directory using Subversion:

sudo svn co http://code.djangoproject.com/svn/django/tags/releases/1.1/django


Installing Django

Now Python should know about Django itself. You’ll only have to tell your system about the django-admin.py so that you can create new projects. To do this, create a symlink:

sudo ln -s /Library/Python/2.6/site-packages/django/bin/django-admin.py /usr/bin/django-admin.py


Cleaning Up

On American Macs, this should already be enough. On many other system, you’ll need one more thing to avoid the dreaded unknown locale: UTF-8 error.

We simple need to set two environment variables to tell your system about your input language. In your terminal, type

nano ~/.profile

which will open your profile file. If there is already something in the file, ignore it. Add these two lines:

export LC_ALL=de_DE.UTF-8
export LANG=de_DE.UTF-8

As you can see, the locale is now de_DE.UTF-8 which is the correct entry for me, as I live in Germany. For other countries, substitute “de_DE” by the correct code as taken from this list of locales.

Save the file by pressing Ctrl+x, then y. Finally, close your terminal and take a deep breath. You have just installed Django on Snow Leopard. Happy coding.

Post to Twitter Auf Twitter posten Post to Reddit Reddit



  1. Jack (Reply) on Dienstag 1, 2009

    Thanks for the tutorial.

    On my clean install of Snow Leopard, though, there’s no site-packages directory at the location you give above, but there is one at /Library/Python/2.6/site-packages/ – I take it it’s okay to install Django there? If not, should I create /usr/local/lib/python2.6/site-packages ?

    • Daniel (Reply) on Dienstag 1, 2009

      Hi Jack,

      that’s strange — I have a fresh and clean install as well, and the site-packages directory was in /usr/local/lib.

      You can find out the correct directory for you by doing the following:
      1. open a terminal window
      2. type python
      3. at the python prompt, enter

      import sys
      print sys.path

      This will print out your python path, which will include at least one directory called site-packages. That’ll be the one. If there are more, you can use any.

      HTH,
      Daniel

  2. Rob Schneider (Reply) on Dienstag 1, 2009

    On my new install of Snow Leopard it is /Library/Python/2.6/site-packages/.

    • Daniel (Reply) on Dienstag 1, 2009

      Thanks for commenting! I changed the article now.

  3. Geof (Reply) on Dienstag 1, 2009

    Any luck getting django working with mysql on snow leopard?

    • Daniel (Reply) on Dienstag 1, 2009

      Should be no problem really. Surely you’ve seen Dan Benjamin’s article on installing MySQL. After following it through, you only need to tell Django to use MySQL in your settings.py file, as in the tutorial.

      Do you have any specific problems?

  4. faiz zaki (Reply) on Dienstag 1, 2009

    Hi . I followed your tutorial on installing django on mac osx leopard. but I’m stuck at syncdb.
    when I run python manage.py syncdb. It give me this error.

    /Library/Python/2.6/site-packages/django_registration-0.7-py2.5.egg/registration/models.py:4: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
    Creating table auth_permission
    Traceback (most recent call last):

    File “/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/MySQLdb/connections.py”, line 36, in defaulterrorhandler
    _mysql_exceptions.InternalError: (1, “Can’t create/write to file ‘/usr/local/mysql/var/test/auth_permission.MYI’ (Errcode: 2)”)

    where did I do wrong ? What shall I do next ?

  5. Paulo Köch (Reply) on Dienstag 1, 2009

    I think this is way more clean:

    curl “http://peak.telecommunity.com/dist/ez_setup.py” | sudo python – -U Django

  6. Mark Raddatz (Reply) on Dienstag 1, 2009

    The simplest way to install django is to create a new isolated python environment with virtualenv and pip anywhere in the path you like.

    $ cd /tmp/
    $ virtualenv mydjango
    $ cd mydjango/
    $ ./bin/easy_install pip
    $ ./bin/pip install django
    $ ./bin/django-admin.py startproject mypony

  7. [...] How to install Django on Mac OS X 10.6 Snow Leopard [...]

  8. Alon (Reply) on Dienstag 1, 2009

    You got ALOT missing. Followed this steps. First my python is /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/

    secondly,

    mysqldb module not found error:

    http://davidmichaelthompson.com/2008/02/18/notes-installing-django-python-mysql-on-os-x/