Setting up virtualenvwrapper

Every time I have to set up virtualenvwrapper, I need to look up the steps, so here they are.

Published: 05/18/2022

Setting up VirtualEnv with VirtualEnvWrapper

Note: This is on Ubuntu 22

First, install virtualenv:

$ sudo apt install virtualenv

Next, install virtualenvwrapper:

$ pip install virtualenvwrapper

I had to find my virtualenvwrapper.sh file:

$ sudo find / -name virtualenvwrapper.sh
/home/scott/.local/bin/virtualenvwrapper.sh

Next, set up the environment variables in your .bash_profile or ~/.bashrc file: (I used .bashrc becuase it was already created on Ubuntu)

export WORKON_HOME=~/.Envs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
source /home/scott/.local/bin/virtualenvwrapper.sh

Once added, I ran source to pick up the changes in my current session and made sure my new directory exists:

$ source ~/.bashrc
$ mkdir -p $WORKON_HOME

Finally, I could run the file and it did some setup:

$ source /home/scott/.local/bin/virtualenvwrapper.sh
virtualenvwrapper.user_scripts creating /home/scott/.Envs/premkproject
virtualenvwrapper.user_scripts creating /home/scott/.Envs/postmkproject
virtualenvwrapper.user_scripts creating /home/scott/.Envs/initialize
virtualenvwrapper.user_scripts creating /home/scott/.Envs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/scott/.Envs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/scott/.Envs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/scott/.Envs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/scott/.Envs/predeactivate
virtualenvwrapper.user_scripts creating /home/scott/.Envs/postdeactivate
virtualenvwrapper.user_scripts creating /home/scott/.Envs/preactivate
virtualenvwrapper.user_scripts creating /home/scott/.Envs/postactivate
virtualenvwrapper.user_scripts creating /home/scott/.Envs/get_env_details

To test, I created a virtual environment:

$ mkvirtualenv test
created virtual environment CPython3.10.4.final.0-64 in 1393ms
  creator CPython3Posix(dest=/home/scott/.Envs/test, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/scott/.local/share/virtualenv)
    added seed packages: pip==22.0.4, setuptools==62.1.0, wheel==0.37.1
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
virtualenvwrapper.user_scripts creating /home/scott/.Envs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/scott/.Envs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/scott/.Envs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /home/scott/.Envs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /home/scott/.Envs/test/bin/get_env_details

Then I verified it:

$ which python
/home/scott/.Envs/test/bin/python
$ which pip
/home/scott/.Envs/test/bin/pip

Done!