Isolated Development Environments with virtualenv


pip install virtualenv

Create a directory for your virtualenvs

mkdir .virtualenvs
cd .virtualenvs

Use virtualenv

Let’s say we want to create a virtualenv called test:

virtualenv test

. test/bin/activate

and the prompt should change to show:


Now, installing a package will install it in this virtualenv. E.g.  pip install pylintwill install pylintinto this virtualenv under .virtualenvs/test/bin

and the PATH is changed so you use stuff under this virtualenv. E.g. which python:


Deactivate virtualenv (also clears prompt with brackets): deactivate

Activate virtualenv: . ./test/bin/activate



pip install virtualenvwrapper

Edit ~/.profile

source /usr/local/bin/

export PROJECT_HOME="$HOME/Code/Python"

This gives us some extra commands – mkvirtualenv, setvirtualenvproject, workon:

mkvirtualenv <virtualenv>

Makes the virtualenv in your .virtualenvs directory.


workon <virtualenv>

E.g. workon test

This doesn’t change us to the code directory though. You can do this by cding to the code directory and using:


This ties the current directory with the virtualenv. Handy if you need to move directories.


mkproject – creates a project in your code directory, sets up a virtualenv, cd’s to the code directory and activates the virtualenv.