Thursday, April 01, 2010

Adventure with Virtualenv

In the python development world, people are using virtualenv, to isolate their python development environment from their system. Why that is cool,
  • You don't conflict with the global python library. Because all new library will be in the isolated environment, on linux many software uses python
  • Then you have a fine grain control of what library is needed what is not, for each environment. 
  • Because all of the cool pythonista use that...ok that is not quite true, but many python based project strongly recommend using virtualenv, such as turbogears. 
  • and some tools are available for this, such as pip. 
  • It make it more easier to move project between directory
Lets get started,
here I assume that python setuptools is installed, i assume each project is one environment
to install, just run below as administrator.
easy_install -U virtualenv
 To start a project
virtualenv projectname
This will setup an environment, with their own setuptools.
Let start using it
 source projectname/bin/activate
and it should have the whole python environment there, isolated from the system. including python, their own site-packages

To stop using it
To totally isolate from the system, start a new project by
virtualenv --no-site-packages projectname
 It will not use library from the system.

Some tools already begin to support virtualenv. Such as pip, a replacement for easy_install, with uninstall support. To use pip with virtualenv
pip -E projectname packagename
So, virtualenv is now the requirement of most project now. Time to learn it...


    1. don't forget to install virtualenvwrapper!, it simplifies managing and working with your virtualenvs,

    2. GOOD IDEA!!!

      Look like a additional tools worth learning