Skip to content


Django

Welcome to the install guide for Django on Mac OSX

Why use this guide instead of the getting started one on DJango’s website? Because Mac OSX’s structure is different from the standard UNIX/Linux/BSD filestructure so if you use the Django Installation guide you’ll encounter a bunch of errors.

Update 22-01-2008: rewrote the 10.4 tutorial. If you’re gonna do python and django you have enough knowledge to use the command-line anyway.

Looking for the 10.4 install guide? It’s just a bit further down this page!

Mac OSX 10.5 / Leopard

This small guide was written on Mac OSX 10.5.1 but should work on every upcoming version of Leopard unless Apple changes quite a few things under the hood. Since Mac OSX 10.5 comes with about all the requirements and the environment properly configured the setup guide for Leopard is very short.

Requirements:

  • Mac OSX 10.5.x (Leopard)
  • iTerm (you can use the Terminal in Application/Utilities too, I like Leopard’s terminal but still prefer iTerm)
  • Subversion
  • Python
  • Django
  1. Download everything
  2. First things first, we need to have a Terminal or iTerm to work with. I still prefer iTerm over Leopard’s terminal, iTerm is available on SourceForge @ iterm.sf.net And that’s it. Mac OS X 10.5 comes with Python 2.5.1 and Subversion pre-configured and all so we won’t need to download and install anything else or mess with the environment variables yet.
  3. Getting Django
  4. First let us create a directory where we want to have Django running from. Since Django is a web-framework it sounds logical to have it running from within your Sites folder. Open a terminal: cd ~/Sites svn co http://code.djangoproject.com/svn/django/trunk django Open a terminal: ln -s ~/Sites/django/django/ /Library/Python/2.5/site-packages/django This sets-up the necessary symbolic link for Python to know where django is. And we’re done, well almost, we still need to tell our PATH environment variable where django’s bin directory is located. Open or create the following file in your homedir: .bash_profile vim ~/.bash_profile or mate ~/.bash_profile Under OS X Leopard there should be nothing in that file so we add the following: PATH="~/Sites/django_src/django/bin:${PATH}" export PATH Now save and close that file. Open a new terminal: echo $PATH Should now return something like this: ~/Sites/django_src/django/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin Now we can start doing stuff, in a terminal: python import django If that returns an error something went wrong, if it did not, you’re done!

Django on Mac OSX 10.4

This guide has been written for Mac OSX 10.4.9 (Tiger) but should work on every release of Mac OSX 10.4 (Tiger). If you have an earlier verion of the OS, such as Cheetah, Puma, Jaguar or Panther this guide won’t be of any use to you.

In this guide I will use precompiled packages to install all the software instead of compiling it from source (shoot me for it :P ) except for Django which will be obtained through Subversion.

Since getting django to work on Tiger is quite a hassle, hence this tutorial will be more extensive than the Leopard one as it requires editing and setting environment variables.

Note: I won’t cover the installation of a database as backend for Django. There are plenty good guides for MySQL for MacOSX, sqlite3 is included in Mac OSX 10.4 (Tiger) The reason I included Python-MySQL is that it is quite difficult if you don’t know where to look for the packages to get them and compiling them yourself is quite the thing too.

Requirements:

  • Mac OSX 10.4.x (Tiger)
  • iTerm (you can use the Terminal isn Application/Utilities too but I hate that thing)
  • a text editor, either use vim (if you know how to) or get TextMate (Mac OSX’s TextEdit won’t do the job)
  • Subversion
  • Python
  • Python-MySQL
  • Django
  1. Download everything
  2. First things first, we need to have a Terminal or iTerm to work with. I would strongely advise you to download and install iTerm, which is available on SourceForge @ iterm.sf.net Now it’s time to get Subversion. Subversion is a version control system and it’s homepage is located at subversion.tigris.org. A Universal Binary is available at Metissian. Download the most recent version and run the installer. Once it is finished eject the .dmg and discard it to you trash. Now it’s time to get Python. Mac OSX Tiger comes with a built-in version of Python but it is extremely outdated. So it’s time to get a new version. Download Python and MySQLdb from Pythonmac.org. When the downloads are finished we first run the Pythin-2.4.4 setup, MacPython.mpkg and then MySQL-Python. Just click through the wizards and accept the defaults.
  3. Checking the installation and configuring the $PATH variable
  4. If everything went well we now have a system ready to run Django. If you had any terminals open, Quit them (Apple+Q) and open a new one. In the terminal enter the following command: python which should result in this output: Python 2.4.4 (#1, Oct 18 2006, 10:34:39) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> If you get a command not found or a Python version prior to 2.4.4 you probably forgot to run the Python-2.4.4 installer or something else went wrong Now enter the following command import MySQLdb If you get an error, MySQLdb isn’t installed and you need to run the installer, if you don’t get any output, just the 3 >>> again, you’re good. Python is now correctly configured and you can exit the Python terminal by hitting Ctrl+D and you will return to normal terminal input. Next in line for a checkup is Subversion. In the terminal enter the following command: svn If you’re lucky you’ll get the following output Type 'svn help' for usage. but if your system behaves like mine, you’ll get the following: -bash: svn command not found For some reason the Subversion installer didn’t edit the path variable and so the terminal doesn’t know the location of svn. Fortunately, we can fix this. In you terminale type: mate ~/.bash_profile to open the file with TextMate or vim ~/.bash_profile and edit the file so it looks like this: # Setting PATH for MacPython 2.4 # The orginal version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/local/bin:${PATH}" export PATH and then save the file and quit the terminal Open a new terminal and type the following command: svn Now you should get the output Type 'svn help' for usage Great, SVN now works too, woohoo :D
  5. Getting Django
  6. Now it’s time to get Django. Open a terminal and go the the directory where you would like to install Django. This can be you Home folder or another location on you harddrive. I decided to install Django in my Sites folder so I entered the following command: cd ~/Sites Once you’ve cd’ed to the directory where you want to download Django enter the following command: svn co http://code.djangoproject.com/svn/django/trunk django_src Now a lot of filenames will scroll through the terminal. Don’t worry, we’re just downloading the code, when finished a message similar to this should appear: Checked out revision 4903. Now Django can be found in ~/Sites/django_rc Once this is done enter the following command: ln†-s†~/Sites/django_src/django/†/Library/Frameworks/Python.framework/Versions/Current/lib/python2.4/site-packages/django Note: in the command I used ~/Sites the directory where django_rc is located, the directory to which you cd’ed earlier This basicaly tells Python where Django is located We’re almost there (thank god). We have got to edit .bash_profile one more time. Enter the following command in your terminal mate ~/.bash_profile to open with TextMate or vim ~/.bash_profile to open with vim and edit the file so it looks like this: # Setting PATH for MacPython 2.4 # The orginal version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:~/Sites/django_src/django/bin:/usr/local/bin:${PATH}" export PATH Note: yet again, /Volumes/Switch is where I decided to locate django_src, change this to suit your needs. Now quit all your terminals and open a new one. Enter the following commands: python import django If you don’t get any errors you’re good and it’s working, if you do get an error, check you didn’t make a typo in the ln -s command and that you changed ~/Sites to where django_src is located on your system. Now hit Ctrl+D to return to a normal terminal prompt. Enter the following command: django-admin.py If you get an error, you did something wrong the last time we edited .bash_profile and if you get a very long list starting with usage: django-admin.py action [options] [...] it means you’ve done everything as you should have and you now have a working Django enviroment installed. Now you can start developement with Django or follow the turtorials over at the DjangoProject website.

I hope this guide has been a useful and an easy to follow one. If you want to leave a comment or a suggestion, pleaso do!


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.