From Code Self Study Wiki
Jump to: navigation, search

Virtualenv and virtualenvwrapper:

Watch a video tutorial:

For Ubuntu:

$ sudo apt-get update
$ sudo apt-get install python-pip
$ sudo pip install virtualenv
$ sudo pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ source /usr/local/bin/

I also put the last two lines in ~/.bashrc and source ~/.bashrc in ~/.bash_profile in order to let the terminal know where to find it.. (GNU/Linux)

For Mac

Visit this tutorial.

Python 3

mkvirtualenv --no-site-packages --distribute -p /usr/bin/python3.3 name_of_virtualenv

Without virtualenv wrapper:

virtualenv -p python3 envname


Put this in your ~/.bashrc file:

alias mkve3='mkvirtualenv --python=`which python3`'

Then you can create new virtualenvs with the command mkve3 name_of_your_venv.


$ mkvirtualenv my_venv

For Python3 with the custom alias:

$ mkve3 my_venv

Remove virtualenv:

$ mkve3 my_venv

List virtualenvs:

$ lsvirtualenv

Activate a virtualenv---you can use TAB completion after typing workon:

$ workon my_venv

Deactivate a virtualenv:

$ deactivate

Upgrade all pip installs:

allvirtualenv pip install --upgrade pip

See more commands in the official docs.


Save to requirements.txt:

pip freeze > requirements.txt

Install into a virtualenv from pip:

pip install -r requirements.txt