Set Up A Wrapper For Venv Environments

To maintain more than one python project at a time we leverage the the builtin python venv tool for creating and using virtual environments.

The venvwrapper package helps to keep the maintenance of multiple virtual environments easier. In short venv is enough, but venvwrapper makes it easier.

Installation

Install the venvwrapper package into your default system Python 3. That is, with no virtual environment active. This installs venvwrapper.sh so that it is available in PATH

sudo pip3 install --break-system-packages venvwrapper

Check that it is indeed available

which venvwrapper.sh

Set up automatic activation of venvwrapper

Add the code snippet below to one or both of these two files.

${HOME}/.bashrc
${HOME}/.profile

Code snippet:

VENV_HOME=${HOME}/.venv
venv_wrapper=$(which venvwrapper.sh)
if [[ -n ${venv_wrapper} ]]; then
    source ${venv_wrapper}
fi

Now Once you open a terminal window you have access to these commands

mkvenv devpi  # create and activate a new virtual environment
venv   devpi  # activate an existing virtual environment
rmvenv devpi  # remove one or more virtual environments
lsvenv        # list existing virtual environments
Published by Pierre Bernatchez in «Infrastructure». Key Words: software, tools