How virtual environments work in Python

By | February 6, 2025

In Python there are generally 2 options for creating virtual environments. (Virtual environments are a must by the way so I won’t go into the pros and cons. Trust me and just use it).

venv

Firstly, there is venv which is shipped with Python so you can think of it as a standard library.

virtualenv

Then there is virtualenv which not part of the standard library. Think of it as a plugin. It can also be thought of as venv but with more features. An easy way to help remember is that venv is a subset of virtualenv just like the 4 character name is a “subset” (not really I know but stay with me here), of virtualenv.

pyenv-virtualenv

Now comes the confusing part. If you are using pyenv (which you definitely should in order to manage your multiple Python environments), then there is pyenv-virtualenv which allows you to use pyenv and virtualenv conveniently at the same time.

There is an argument that after Python 3.3, pyenv-virtualenv will try to run python -m venv if it is available, instead of virtualenv. And it can get even more confusing at this post points out.

But the main point is to use one and get your code working. That is the most important thing. Then when it working, you can explore other funky methods of doing the same thing.

pyenv virtualenvs

The first command you want to run is pyenv virtualenvs which list the current virtual environments available.

Leave a Reply

Your email address will not be published. Required fields are marked *