Using Python Virtual Environment - venv

Once in a while I need to use python. In order to avoid distribution related global packages, I use venv to install packages locally as it doesn't require additional installation.

Create a virtual environment for python.

python -m venv venv

This will create a folder called venv which will include scripts to help you activate to an apporpriate version of python. If you would like to use a different folder you can use python -m venv myvenvfolder.

To activate the environment run the following command in unix shells.

source ./venv/bin/activate

For cmd.exe in windows use .cmd file instead.

./venv/Scripts/activate

For PowerShell use the .ps1 instead.

./venv/Scripts/Activate.ps1

To exit out of the virtual enviornment run the following command.

deactivate