/ python

Virtualenv with Python

Thanks to virtualenv project dependencies like libs are then isolated from other projects and OS system packages.

This means, a virtualenv will encapsulate everything which belongs to a project and keeps it local.
On Ubuntu this can be setup in the following way:


Python 2:

Install Venv support

$ sudo apt-get install python-virtualenv

Create a new virtualenv:

$ virtualenv <virtualenv-name>
Python 3:

Install Venv support

sudo apt-get install python3-venv

Create a new virtualenv:

$ python3 -m venv <virtualenv-name>

Activation of the Virtual Environment:

$ source ./<virtualenv-name>/bin/activate

From that time on the python binaries will be used from the venv folder. Additionally all module installations will be done with this folders.

A check with which python3 will then give


Store current environment

To keep the current module & library installations consistent, the environment can be frozen - this means to list all modules with their versions for reproducible installation afterwards:

$ pip freeze > requirements.txt

Install all modules with their listed versions again:

$ pip install -r requirements.txt