venv for Dummies
This is a compressed cheat sheet for venv:
Create Environment
python3 -m venv path/to/env
Creates a new environment in a specific folder, using current python interpreter (python3
). It’s not activated by default.
You might need to install it first on distros that don’t have it by default i.e. apt install python3-venv
.
Activate
To use that environment, you need to activate it.
On Linux, you would run activate
script form the bin
folder in that env:
. path/to/env/bin/activate
A hint it’s active is prompt change in most of the shells i.e. bash:
(env) aloneguid@sb:~/path/to/env$
On Windows venv
usually does not create bin
folder but Scripts
and you can run Activate.ps1
:
C:\path\to\venv\Scripts\Activate.ps1
On Mac, run source venv/bin/activate
.
Deactivate
On Linux, execute deactivate
. In fact, this also works on Windows as well, due to some trickery venv adds to Scripts
folder.
To contact me, send an email anytime or leave a comment below.