I know that many people use venv
nowdays but the functionality of just using mkvirtualenv
to make a new virtual environment and just using workon
to get a list of available envs and working on them has prompted me to stick to virtualenv itself.
What worked for me in my Ubuntu 20.04 LTS:
sudo apt install virtualenv
Don't use pip install virtualenv
as it does not automatically set the path.
Create a directory to store all your virtual envs using:
mkdir .virtualenv
Install the virtualenvwrapper using:
pip3 install virtualenvwrapper
Modify your .bashrc file by adding the following commands:
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source ~/.local/bin/virtualenvwrapper.sh
Source the .bashrc file using :
. ~/.bashrc
in your terminal.
Restart your terminal and create a virtual environment using:
mkvirtualenv name-of-env
The environment is activated upon creation and appears as
(name-of-environment)user@sys-name:~$
To deactivate the environment just use :
deactivate
in your terminal.
Now you can access the list of environments using workon
and activate them by simply using:
workon name-of-environment