Why is virtualenv necessary?

A Virtual Environment, put simply, is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects.

For example, you can work on a project which requires Django 1.3 while also maintaining a project which requires Django 1.0.


Virtualenv keeps your Python packages in a virtual environment localized to your project, instead of forcing you to install your packages system-wide.

There are a number of benefits to this,

  • the first and principle one is that you can have multiple virtulenvs, so you can have multiple sets of packages that for different projects, even if those sets of packages would normally conflict with one another. For instance, if one project you are working on runs on Django 1.4 and another runs on Django 1.6, virtualenvs can keep those projects fully separate so you can satisfy both requirements at once.
  • the second, make it easy for you to release your project with its own dependent modules.Thus you can make it easy to create your requirements.txt file.
  • the third, is that it allows you to switch to another installed python interpreter for that project*. Very useful (Think old 2.x scripts), but sadly not available in the now built-in venv.

Note that virtualenv is about "virtual environments" but is not the same as "virtualization" or "virtual machines" (this is confusing to some). For instance, VMWare is totally different from virtualenv.