Skip to content

Instantly share code, notes, and snippets.

@omaciel
Last active July 27, 2016 20:22
Show Gist options
  • Save omaciel/dbba7fb080c475a421be to your computer and use it in GitHub Desktop.
Save omaciel/dbba7fb080c475a421be to your computer and use it in GitHub Desktop.
How to create and use Python virtual environments for development

Creating a Python Virtual Environment

Install virtualenv and virtualenvwrapper

$ sudo pip install virtualenv virtualenvwrapper

Add the following lines to your $HOME/.bashrc

# Virtualenv
export WORKON_HOME='/Users/omaciel/hacking'
source '/usr/local/bin/virtualenvwrapper.sh'

Create a new virtual environment

$ mkvirtualenv -a <path of project>  <env name>

Create a new virtual environment and choose version of python

$ mkvirtualenv -a <path of project>  -p <python to use> <env name>

Create a new virtual environment automatically installing dependencies

$ mkvirtualenv -a <path of project>  -r requirements.txt <env name>

Deactivating a virtual environment

$ deactivate

Activating a virtual environment

$ workon <env name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment