Show Menu
Cheatography

Python Virtualenv Cheat Sheet (DRAFT) by

How to set up and use a virtual python environment in Ubuntu

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Instal­lation using setuptools and pip

Install Easy Setup
or
Install PIP
sudo easy_i­nstall pip
Turn on bash autoco­mplete for pip
pip completion --bash >> ~/.bashrc
Enable bash pip completion
source ~/.bashrc

install virtualenv and virtua­len­vwr­apper

sudo pip install virtualenv
sudo pip install virtualenvwrapper

Setup virtualenv

export WORKON_HOME=~/.virtualenvs

mkdir $WORKON_HOME

echo "export WORKON_HOME=$WORKON_HOME" >> ~/.bashrc

Setup virtua­len­vwr­apper

echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc

echo "export PIP_VIRTUALENV_BASE=$WORKON_HOME" >> ~/.bashrc 

source ~/.bashrc
 

Use Virtualenv

Create blank env
mkvirt­ualenv <vi­rtu­al-­env­iro­nme­nt-­nam­e> --no-s­ite­-pa­ckages
Switch env
workon <vi­rtu­al-­env­iro­nme­nt-­nam­e>
Leave Virtual env
deactivate
Manually switch env
<vm­-fo­lde­r>/­bin­/source activate
Remove Env
rmvirt­ualenv <vi­rtu­al-­env­iro­nme­nt>