How to create your custom virtualenv installation that include the packages of your choice 2012-08-15

I use virtualenv all the time, for every new project, for every lib or project I test. I also use ipython and ipdb all the time (and django nearly all the time).

Problem: ipython, ipdb and django aren't shipped by virtualenv and installing them took some time that break my flow when I need them.

Luckily, mitsuhiko has release virtualenv-tools that allow you to update the path of a copied virtualenv.

Some small shell scripting later and here is the result:

mkve ()
    [ -e "$(which pip)" ] || (echo "installing pip"; sudo aptitude install python-pip)
    [ -e "$(which virtualenv)" ] || (echo "installing pip"; sudo pip install virtualenv)
    [ -e "$(which virtualenv-tools)" ] || (echo "installing virtualenv-tools"; sudo pip install virtualenv-tools)
    if [ ! -e ~/.myvirtualenv/ ]
        virtualenv --distribute ~/.myvirtualenv/
        ~/.myvirtualenv/bin/pip install ipdb django django_pdb django_extensions django_debug_toolbar
    cp -r ~/.myvirtualenv/ ve
    virtualenv-tools --update-path $(pwd)/ve ve
    source ve/bin/activate

Just type mkve, it will check that you have everything needed installed then build the virtualenv if it isn't there, install the packages in it then copy this virtualenv to your current directory, update its paths and activate it.

It's even faster than to build a new virtualenv (once the global virtualenv is created).