python-guide.pdfVirtualenv is a Virtual Environment tool to keep the dependecies requied by different projects in seprarate places, by creating virtual Python environments for them. This solves the "Project X depends on version 1.x but Project Y needs 4.x" dilemma.

Getting Started

Virtual Environments on Python 2.7

  •  Create a virtual environment in your current directory for a project with the command: virtualenv my_project
    • "my_project" is whatever name you would like to give this enviornment
  • To create a virtual environment with a specific version of python use the command: virtualenv -p /usr/bin/python2.7 my_project
    • "python2.7" can be replaced with the version you would like to use

Virtual Environments on Python 3.5+

  • Create a virtual environment in your current directory for a project with the command: python3.5 -m venv my_project
    • "my_project" is whatever name you would like to give this enviornment

Using the Virtual Enviornment

Bash shell:

  • Start the virtual environment by activating with the command: source my_project/bin/activate

csh /tcsh:

  • Start the virtual enviornment by activating with the command: source my_project/bin/activate.csh

Pip can now be used as usual for package installs

  • When you run 'python' it will be the version specified in Step 1
  • When you run 'pip', you're running the correct version
  • All modules are installed inside that environment

When you are finished working in the evironment, exit using the command: deactivate

For more details visit:  http://docs.python-guide.org/en/latest/dev/virtualenvs/ 

or download the PDF:  python-guide.pdf