Mac OSX — Installing a fresh Django environment with Homebrew, Git, and Virutualenv


How to install an isolated Django environment with Homebrew, Git, Virtualenv on OSX 10.6.5

I needed to start a local development environment, and every time I make a major switch whether it be a new server or a new OS, I try to make improvements based on what I’ve learned since the previous switch.

This time, I decided I need completely isolated virtualenvs, and I needed my code rewritten to use relative paths so that I can actually run my django app in my local environment without any changes.


First, install homebrew

I need the package manager Homebrew to do easy installs of various things like wget, Git, that are missing.

ruby -e "$(curl -fsSL"

Next, install Xcode

You can find Xcode on the CD that ships with your mac.

Just open the CD, go to the Optional Installs folder, and click on the Xcode package.

This post has more detail if you require it

Homebrew some Git

brew install git


Use easy_install to grab virtualenv

easy_install virtualenv

Finally, time to set up our project!

First, we need to set up our project folder. I shall call it myproject. Very original.

mkdir myproject 
cd myproject

Now, it’s time to set up the virtual environment. I’m going ot use the –no-site-packages option to completely isolate this environment from the global python site-packages living in /Library/Python/X.X/site-packages

virtualenv venv --no-site-packages  # isolate from packages
cd venv  # cd into our newly created venv

virtualenv has set us up (the bomb) with a lib/ directory where python2.6 lives, and a bin/ directory where we have the activation scripts that force us to use this environment.

Since we want to install django into this virtualenv, run the bash script “bin/activate”

source bin/activate

Now we can install django. It’s now as easy as typing …

easy_install django

We can install most packages this way..

PS: I’d like to note that I had trouble installing PIL due to a bug. As of Nov 20, 2010, easy_install PIL will install to the correct directory but will not work. All you need to do is symlink the funky egg file to the same directory under the name PIL.

easy_install PIL
ln -s PIL............ PIL

Now we’re ready to start the django project.

cd ~/myproject
source venv/bin/activate # MAKE SURE you have activated your virtualenv, or else your python can't find the django you just installed. startproject main

Congrats! Your isolated django install is ready on OSX


8 thoughts on “Mac OSX — Installing a fresh Django environment with Homebrew, Git, and Virutualenv

  1. Thank you very much for posting this. It saved me a lot of time. This was accurate, concise and best of all it works.


  2. Thanks!


    I didn’t have to do the “PIL” symlink. Perhaps they have fixed that bug?

    Also, I used this with my first django project and at first I was getting a slew of errors followed by:

    django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb


    easy_install MySQL-python

    1. It looks like for this example I used the home folder (~/), but it doesn’t matter where you put it. It shouldn’t be accessible by the web ; )

      On OSX, my typical setup is ~/Projects/myproject/

      In my production sites, I use/srv/myproject/.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s