What is Virtualenv

Virtualenv is a tool to create isolated Python environments.

Its usage could be very useful when dependencies and versions are tricky. Imagine you have an application that needs version 1 of a library, but another application requires version 2. If you install everything into /usr/lib/python2.7/site-packages (the standard place where all packages are installed), then you may upgrade a library that shouldn’t be upgraded.
Besides, what if you can’t install packages into the global site-packages directory because of restricted permission ?

In these cases, you can use virtualenv to create an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments (and optionally doesn’t access the globally installed libraries either).

To create a virtual environment, type:

virtualenv --no-site-packages <directory>


virtualenv <directoy>

The former version (with –no-site-packages) will not even use any of the already installed packages in /usr/lib/python/site-packages.

Then to activate an environment, simply go into it and activate it:

cd <directory>
source ./bin/activate

From now, when you install a python packages, it will be installed in /lib/python/site-packages

See Virtualenv website for more details.

Please follow and like us:
This entry was posted in Python and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.