NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

Creating and Using a Virtual Python Environment

What We Are Trying To Do

Your computer's system Python is used by your computer's operating system for many things including installing your OS itself and installing additional software on your OS. It is not good to pollute that Python with your own packages, and Python packages which your OS uses might interfere with your own packages.

Also, your computer's Python might not even be the right version for packages you want to use.

You may need many different versions of Python on your computer for doing different things.

You may also need different versions of Python packages for doing different things.

You may also find you have installed a Python package you don't like for some reason. You need a way to get rid of Python packages you don't want.

You want to do two things:

  1. Use the right version of Python for your job.
  2. Isolate the Python packages used by your applications for each application.

Some terminology if you get lost:

ez_setup.py
A Python module which installs the setuptools package and the ez_install executable.
ez_install
An executable in your Python's bin directory which can automatically install Python packages.
setuptools
A Python package which facilitates creating and distributing third party Python packages.
distutils
A Python package which is the predecessor of setuptools still in wide use.
setup.py
A Python module which, when placed at the top level of a Python package, tells setuptools or distutils how to install the package. It normally consists of one function call (setup()) with numerous arguments. setup.py is defined by the package author.
Pypi
The Python Package Index (aka "Cheeseshop"). A master repository of third party Python packages. ez_install downloads packages from Pypi by default. Pypi contains packages in both "egg" form created by setuptools and zipped packages created by distutils.
egg
A zipped file created by setuptools which contains a distributable form of a Python package.
site-packages
A subdirectory in your Python's lib directory which contains your installed third party Python packages.

There are three places to start:

  • If you don't yet have a Python compiled separately from your system Python,
  • If you have a Python instance separate from your system Python, but it doesn't yet have the setuptools package installed, or
  • If you already have a separated compiled Python with the setuptools package installed.

If you don't yet have a Python compiled separately from your system Python

  • XXX
  • Proceed to:

If you have a Python instance separate from your system Python, but it doesn't yet have the setuptools module installed

  • Get the latest version of ez_setup.py (Right click to save as python file)
  • Run ez_setup.py with your separately compiled Python: /usr/local/python2.6/bin/python ez_setup.py
  • Your separately compiled Python's bin directory will now contain a new executable called ez_install
  • Proceed to:

If you already have a separated compiled Python with the setuptools module installed

  • Install virtualenv with ez_install: /usr/local/python2.6/bin/ez_install virtualenv
  • Your separately compiled Python's bin directory will now contain a new executable called virtualenv