Aaron Presley

← Writing
Setting up Django on Mac OS X 10.9

April 20, 2014

It took me some time to figure out the best way to get Django going on my Mac OS X 10.9. Here is a guide to what I eventually started doing.

Setup Python, pip, and virtualenvs

Apple has a tendency to change the Python core at-will, so I think it's best to follow this guide and install a vanilla copy of Python. The basic commands are below, but it'd probably best to read the whole guide:

Python Environment

brew install readline sqlite gdbm brew install python

At this point, ensure that /usr/local/bin is being loaded before /usr/bin in your ~/.bash_profile

Installing Pip & Virtualenv

sudo easy_install pip pip install virtualenv pip install virtualenvwrapper

Add this to your ~/.bash_profile:

export WORKON_HOME=~/.virtualenvs/
source /usr/local/bin/virtualenvwrapper.sh

Reload your profile with source ~/.bash_profile, and ensure that your current Python install is pointing to the /usr/local/bin directory (do this by running which python).

First Django Project

We'll need somewhere to hold the actual files for this project, so we run mkdir ~/Scripts/NewProject && cd ~/Scripts/NewProject

Each Django project is contained within a virtual environment. This allows you to easily have multiple projects on your system with different Django versions. Create a virtualenv for our new project:

mkvirtualenv newProject

Your terminal prompt will now look something like: (newProject) NewProject$. That means we're currently in our newProject virtualenv, and are inside the NewProject folder.

Now let's install Django using pip with pip install django. Now we'll start our new project python manage.py newproject.

That generates a bunch of files in ~/Scripts/NewProject, and you now have an empty Django project. Done!