Python in a shared hosting environment

Filed under: python easy_install 

Lots of people like to use virtualenv, but personally I like using the method outlined on the easy_install section of the PEAK guide. I've shortened the instructions here to make them specific to Python 2.5 and POSIX systems (I have no idea how well this works on Windows, nor do I care much).

First, create an altinstall.pth file in Python's site-packages directory, containing the following:

import os, site
site.addsitedir(os.path.expanduser('~/lib/python2.5'))

This will automatically add each user's ~/lib/python2.5 directory to sys.path (if it exists), and it will process any .pth files in that directory.

The next step is to create or modify distutils.cfg in the distutils directory of your Python library. The correct directory will be something like /usr/lib/python2.5/distutils on most Posix systems:

[install]
install_lib = ~/lib/python2.5
install_scripts = ~/bin

This will configure the distutils and EasyInstall to install packages to the user's home directory by default.

The next step is to prevent these changes from affecting the root user (since usually root will be installing packages system-wide).

Create a file named .pydistutils.cfg in root's home directory (usually /root):

[install]
prefix=/usr
install_lib=/usr/lib/python2.5/site-packages
install_scripts=/usr/bin

[easy_install]
site-dirs=/usr/lib/python2.5/site-packages


0 comments Leave a comment