Python venv


Create

Create Python 3 virtual environment:

python3 -m venv <myenv>

For example, you can create a virtual environment directory named venv:

python3 -m venv venv

Activate

Activate your virtual environment:

source <myenv>/bin/activate

Verify your python and pip binaries:

which python # path/to/venv/bin/python
which pip # path/to/venv/bin/pip

Install

Install from requirements.txt:

pip install -r requirements.txt

Install package black:

pip install black

Save dependencies to requirements.txt:

pip freeze > requirements.txt

Deactivate

Deactivate your virtual environment:

deactivate

Git

Append your virtual environment directory to .gitignore:

echo <myenv> >> .gitignore


Please support this site and join our Discord!