Getting Virtualenv to Run on Your Mac

I've seen a lot of chatter on the django-user-groups about using the virtualenv utility. If you're running multiple apps on various environments, maybe one on Django v96 and something slightly newer on Django v1.02, virtualenv can be a lifesaver.

In the past I would download and setup various packages while not installing them globally. Thus, whenever working on a particular app I would have to make sure to change my PYTHONPATH with various set/alias commands. Now, with virtualenv, it's a little easier to develop an app with its own local environment. Each "virtual environment" you will have your own python executable and site-packages, keeping everything nice and isolated when you're testing out new doo-dads.

Here, I'll go over the few steps needed to get virtualenv up and running on a Mac. First install pip. Then on the terminal type the following:

donnie-demuths-macbook-air:Sites donnie$ sudo pip install virtualenv
Password: *******
Downloading/unpacking virtualenv
Downloading virtualenv-1.3.3.tar.gz (1.0Mb): 1.0Mb downloaded
Running egg_info for package virtualenv
Installing collected packages: virtualenv
Running install for virtualenv
Installing virtualenv script to /usr/local/bin
Successfully installed virtualenv
donnie-demuths-macbook-air:Sites donnie$
Unfortunately, if you don't have xcode installed yet you will need to get it. It's a real pain because the file is so HUGE (2.5GB+) and it's mandatory. You can get evil xcode here but be sure to remember you apple ID and password. Btw, I hate any mandatory huge files that I don't really want.

Using virtualenv may seem confusing and will probably take a bit of tinkering around. I suggest trying the following:
virtualenv MyFirstEnv

This will create MyFirstEnv/lib/python2.X/site-packages and MyFirstEnv/bin/python. To start using this environment, use the source command.
source MyFirstEnv/bin/activate

Now you when install any new packages using easy_install or pip it will be installed to the MyFirstEnv environment rather than globally! To get out of this environment, you can go back to global by using the deactivate command.

Working with virtualenv -- Arthur Koziel
Justin Driscoll: Setting Up A Django Development Virtual Environment on OS X