Setting up a Python virtual environment

IMO the many versions and dependencies in Python make it highly fragmented and fragile. Using Python Virtual Environments, the programmer can rapidly experiment with different versions and dependencies in a VE, without disrupting the computer operating system.

Create a project directory and move into it

$ mkdir piper; cd piper

Check Python version

$ python3 -V
Python 3.8.10

Install Python VENV

$ sudo apt install python3.8-venv

Create virtual environment

$ python3 -m venv .venv

Activate the virtual environment

source .venv/bin/activate

To deactivate the virtual environment just type deactivate

$ deactivate

Different version of Python for your Python Virtual Environment

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.9 python3.9-venv python3.9-dev

Create a PVE for the new version

$ python3.9 -m venv new_venv

Activate the new PVE

$ source new_venv/bin/activate