How and why use buildout with virtualenv

Buildout is this wonderful tool which helps you to automate setup and configuration of your applications.

Virtualenv is a tool which will help you to isolate your python environment

A few days ago I got stuck during a long time because I didn’t see that one library I installed in my global site-packages of my favourite python 2.4 (on my ubuntu: /usr/lib/python2.4/site-packages/) was a lower version of a library I was using in my buildout. Package was sqlalchemy 0.4 in my global sites-package and my buildout based application was using sqlalchemy 0.3.8 … Here is a simple solution to avoid this kind of things.

Idea is to start buildout with a python free of any external library. Virtualenv is the answer.

Install Virtualenv

Easy:

$ easy_install virtualenv

you will have then a file that you can run: /usr/bin/virtualenv

Let’s say you have a buildout configuration go into it:

$ cd myApp.buildout
$ ls -l
bootstrap.py
buildout.cfg

Now you just have to create the python environment without any access to the global site-packages with virtualenv:

$ virtualenv --no-site-packages .

You will have then your new python in the bin folder :

$ ls -l bin
activate
easy_install
easy_install-2.4
python2.4

You can now run the buildout configuration with your new python:

$ ./bin/python2.4 bootstrap.py
$ ./bin/buildout

This will create you a nice and totally isolated environment …