Python: Creating a virtual environment
virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.
Note: If you are using Python 3.3 or newer, the venv module is the preferred way to create and manage virtual environments. venv is included in the Python standard library and requires no additional installation.
Installing virtualenv
python3 -m pip install --user virtualenv
Creating a virtual environment
python3 -m venv env
Activating a virtual environment
source env/bin/activate
Install packages
pip install -r requirements.txt
Freeze requirements
pip freeze > requirements.txt
Leaving the virtual environment
deactivate
Reference: