Cheatsheet virtualenvwrapper

This is a cheatsheet for virtualwrapper.

Install virtualenvwrapper

pip install virtualenv

pip install virtualenvwrapper-win

Set environment variable

Add an environment variable WORKON_HOME to specify the path to store environments. By default, this is %USERPROFILE%\Envs. I have set it to the following.

WORKON_HOME=%PYTHON27%\env

Main commands

mkvirtualenv <name>

lsvirtualenv

workon <name>

cdvirtualenv

deactivate

add2virtualenv <full or relative path>

setprojectdir <full or relative path>

cdproject

cdsitepackages

lssitepackages

 

Cleanup the default Python environment

I have been messing around with Python these last few weeks. Playing with Python means installing a lot of packages. I did this without using virtualenv, so my default Python environment had a lot of packages installed globally.

I now have a couple of projects that I want to work on and I what each project to have its own clean environment. That means using virtualenv. When running virtualenv without with the option --no-site-packages all the packages that are installed globally are included in the virtualenv.

I wanted to remove all the global packages to have a clean default environment. I did this by running the following command.

Windows

pip freeze > remove.txt && pip uninstall -y -r remove.txt && del remove.txt

Linux

pip freeze > remove.txt && pip uninstall -y -r remove.txt && rm remove.txt

After cleaning up the default envrionment by removing all the global packages don’t forget to install virtualenv en virtualenvwrapper-win by running the following command.

pip install virtualenvwrapper-win

For quick instructions of the main commands please check out virtualenvwrapper-win Github page.