Python Virtual Environments
Create python environments for specific app/tooling needs. Used commonly to prevent scripts/apps from munging systemwide Python installation.
Creating Environment
See python pip and virtual environment for reference material.
apt install python3-pip python3-venv
test -d {ENV DIR} || python3 -m venv {ENV DIR}
Note
All other virtual environment commands are deprecated now.
export PIP_REQUIRE_VIRTUALENV=true
Using Virtual Environments
. {ENV DIR}/bin/activate
deactivate
Export/Import Environments
Environments may be exported for easy configuration with services and scripts.
. {ENV DIR}/bin/activate
python3 -m pip freeze > {ENV CONFIG}
. {ENV DIR}/bin/activate
python3 -m pip install --requirement {ENV CONFIG}
Updating Environments
Update environment and re-export.
. {ENV DIR}/bin/activate
python3 -m pip install --upgrade --requirement {ENV CONFIG}
python3 -m pip freeze > {ENV CONFIG}
References