Nice to Know About Virtualenvwrapper
Since I'm mostly working on various Django projects I am working with virtualenv/virtualenvwrapper a lot. It allows to encapsulate environments and keep them identical across all servers your app will run on.
The Problem
All this means setting up pretty much the same Python environment over and over again:
- create an environment
- enter environment
- install pip
- install IPython
- install Django
- install psycopg2
- install PIL
- install south
- install sorl-thumbnail
- install django-compress
- install all project specific packages and django apps
Quite tedious after your nth project really.
The Solution
After reading how virtualenv allows bootstrapping environments and as such reducing tedious work I wondered if that can be done with virtualenvwrapper, too. Turns its absolutely possible.
There actually are quite a few hooks in virtualenvwrapper that allow for stuff being run pre- and post- creating/deleting/activating environments. Now my postmkvirtualenv script looks like this:
#!/bin/bash
Now whenever I create an environment with mkvirtualenv someproject all my standard Python packages and Django apps get installed automagically. And then I'm able to put something like this in my postactiveate script:
#!/bin/bash
So whenever I activate my environment with workon someproject I get beamed right into my project dir and can start hacking right away. Nice and easy.