virtualenv

Contents

virtualenv#

Instead of the built-in venv module, virtual environments can also be managed with the PyPI package virtualenv, which is in some sense its pre-cursor. It offers some additional features and is for instance used by other tools like pipenv and poetry. But in most cases there’s no need for an additional dependency and the Python built-in venv is sufficient.

Usage#

The syntax to manage virtual environments is similar to venv.

$ virtualenv .venv           # create new virtual environment .venv
$ source .venv/bin/activate  # activate the virtual environment .venv
$ deactivate                 # deactivate the current virtual environment

When juggling multiple Python versions, you can specify the python executable for the virtual environment.

$ virtualenv -p python3.11 .venv    # create .venv for the given python interpreter