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 https://gist.github.com/raw/323731/install_homebrew.rb)"
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 http://www.mactricksandtips.com/2010/02/installing-xcode.html
Homebrew some Git
brew install git
Use easy_install to grab 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”
Now we can install django. It’s now as easy as typing …
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. django-admin.py startproject main