Python 3.6 and Virtual Environments

Since python 3.6 there is a new way to create and use virtual environments. The old way was by:

Installing virtualenv:

sudo apt install virtualenv

and then create environments in a given folder by:

cd /home/user/environments

virtualenv -p python2 tensorflow2
virtualenv -p python3 tensorflow3

then activating by:

source ./bin/activate

and finally at the end of the usage deactivate by:


Since python 3.6 you can use venv module:

To create a virtual environment:

python3 -m venv tensorflow2
python3 -m venv tensorflow3

Activation is done by:

source tensorflow3/bin/activate

The requirement management with pip is the same as the virtualenv. With pip freeze you can get list of all requirements:
(tensorflow2) $ pip freeze > requirements.txt
(tensorflow2) $ cat requirements.txt

Install new modules is done by:

(tensorflow2) $pip install numpy

With a specific version:

(tensorflow2) $pip install pandas==0.19.0

View information for a given package:

(tensorflow2) $pip show pandas

View all installed dependencies by:

(tensorflow2) $pip list

if you don't see the virtual environment name then you are not using this virtual environment:

(tensorflow2) $ pip list

not using:

$ pip list

Deleting or removing virtual environment is done the same way by:

  1. Deactivate the environment
  2. Delete it with:
$ rm -rf tensorflow2

Related Article