The module that is used to create and manage virtual environments is called venv. Follow these steps to create a virtual environment and to activate it:
1. Install venv using the following command:
sudo apt install python3-venv
2. Choose a directory to create a virtual environment, and run the venv module with the directory path.
python3 -m venv virtual_environment_directory
This will create the virtual_environment_directory directory if it doesn’t exist, and also create directories inside it containing a copy of the Python interpreter, the standard library, and various supporting files.
3. Once a virtual environment is created, you may activate it using the following command: