Python and Easy Install

This support document describes how to use Python 2.6 and Easy Install. A virtual Python environment is created which uses local library directories, allowing you to install custom Python packages.

Creating a virtual Python environment

First, we will create a virtual Python 2.6 environment in ~/v/ (you can use any prefix you want, even your home directory):

virtualenv ~/v/

If Python 2.6 is not installed on your server, create a virtual Python 2.5 environment instead.

wget http://peak.telecommunity.com/dist/virtual-python.py
/usr/bin/python2.5 virtual-python.py --prefix ~/v/

Then, we will install setuptools which will install the easy_install script:

wget http://peak.telecommunity.com/dist/ez_setup.py
~/v/bin/python ez_setup.py

You can now install any Python packages using ~/v/bin/easy_install. For example, the following command will install the MySQL Python module required for Django:

~/v/bin/easy_install MySQL-python

Making it default

To use your virtual Python environment in the shell by default, add the following lines to your login script (i.e. ~/.bashrc or ~/.zshrc in case of zsh):

alias python=~/v/bin/python
alias easy_install=~/v/bin/easy_install

If you install ipython (~/v/bin/easy_install ipython) you will want to include that as well.

After logging in again, the changes will take effect and you can now simply type python to use your local Python installation.

To use your Python environment on your Django deployment site, modify the Django start script (which is in ~/init) and set DAEMON to your Python binary:

DAEMON=/home/username/v/bin/python

External links

A project of wservices.ch A project of wservices.ch