Python environments can get complex and problematic without virtual environments. We can use venv module that comes built-in with Python to manage it, but it may get complex too after a while. For these needs specifically, virtualenvwrapper has been developed.
Install virtualenvwrapper with pip
sudo pip3 install virtualenvwrapper
Virtualenvwrapper uses a sh file to initialize all the commands that we are going to use. In order to make it executable at the beginning of all sessions, we are going to add it to the .bashrc
But first, we need to know where it is. To check the location of the
virtualenvwrapper.sh, run the command below.
Output on my system is as follows.
In order to add it to the
.bashrc run the following commands, do not forget to replace the location if it is
echo 'export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3' >>~/.bashrc echo 'export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv' >>~/.bashrc echo 'source /usr/local/bin/virtualenvwrapper.sh' >>~/.bashrc exec "$SHELL" echo $WORKON_HOME
When we execute
echo $WORKON_HOME if we can get a location to a
.virtualenvs directory, it means that our
installation was successful.
In order to create a virtual environment, you can use the
mkvirtualenv command with a name of your choice for your new
As can be seen above, a new virtual environment is created and activated. If we check the locations of python and pip we can see that they are pointing to a different location than the system locations. Also, we can validate that we are working on a different environment by checking the installed pip packages.
We can list the available virtual environments with the
Also, we can activate the virtual environment of our choice with the
workon command with the name of our virtual
In order to deactivate a virtual environment, you can use the
deactivate command. You can check if a virtual
environment is activated or not by checking the beginning of your terminal name.