Virtual Environment

Virtual Environment is a tool used to create an isolated environment for Python projects. This means that each project can have its own dependencies, regardless of what dependencies every other project has.

For more information, refer to https://docs.python.org/3/tutorial/venv.html

Install Python

To check if python is already installed, go to your shell and execute.

py --version

Note

If you have python 2 installed, the default value returned in 2.7.4. To check which version of python 3 you have by default, execute:

py -3 --version

If a version 3.5.x or 3.8.x is returned, continue creating the virtual environment. Else download python 3.5.x or 3.8.x from https://www.python.org/downloads/

Create Virtual Environment

To create a new virtual environment, please run the following:

py -3.8 -m venv <DESTINATION>

This will create a new virtual environment using Python 3.8.0 (use -3.5 if you need Python 3.5.x instead) in the destination directory given.

A virtual environment is self contained within the destination directory and must be explicitly activated to be used.

Activate Virtual Enviroment

To activate it, you will need to execute a script which varies depending on your shell.

  1. Windows / bash

    source <DESTINATION>/Scripts/activate
    
  2. Windows / cmd

    <DESTINATION>/Scripts/activate.bat
    
  3. Windows / powershell

    . <DESTINATION>/Scripts/activate.ps1
    
  4. Linux / any (Note : We do not support Linux at the moment)

    source <DESTINATION>/bin/activate
    

Once the virtual environment is activated, the name of your virtual environment will appear on left side of terminal. This will let you know that the virtual environment is currently active.

../../_images/virtualEnvironment.PNG

Deactivate Virtual Enviroment

To Deactivate the virtual environment, you will need to execute the following command on your shell.

Deactivate