VENV

venv is Python’s built in virtual environment manager. The weirdest thing for me about python development has always been virtual environment/virtualenv management.

So which is it? virtualenv? Or pyenv? Or should I use pipenv? What about poetry?

Luckily, python stdlib does have a built in solution for this, making things boring and hopefully settling some debates about which to use. It’s venv.

There should be one-- and preferably only one --obvious way to do it.

It’s LITERALLY built into the language!

How to use it?

python3 -m venv venv

This initializes a virtualenv in the venv dir of whatever dir this was run in.

Then you can run this command:

source venv/bin/activate

and if that works you’ve entered the ‘venv’ python interpreter

From there, you can run:

pip install -r requirements.txt

Or similar, and it will all be scoped to the current dir.

Also,when you want to ‘select interpreter’ (say for vscode) you just need to select the venv/bin/python of the venv you just created.

end of storey Last modified: