Installing a Python package locally on a linux box

Posted: Thu 10th Mar 2011@11:01

I recently needed to install a python module on server for which I don't have Admin privileges. It took a while, but by reading the python guide, and a forum post about creating linux environment variables, I managed to get it to work. (In this case, Ubuntu Server 10.?

Step 1.

Get the package you want to install - in my case, matplotlib.

wget http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0.1/matplotlib-1.0.1.tar.gz


Unzip/tar/gz it:
gunzip -c matplotlib-1.0.1.tar.gz | tar xf -



Step 2.

CD into the directory, and install it to the directory of your choice. tilde (~) will install it into your home directoty, uder /home/{username}/lib/python/{modulename}

cd {unzipped directory}
python setup.py --home=~

Step 3.
Set environmental variable for PYTHONPATH so that python searches this location for packages.

I chose to use the .bash_profile method as follows.
In your home directory, open the .bash_profile file, if it does not exist, you can create it.
Add the following:

PYTHONPATH=~/lib/python/
export PYTHONPATH

Where ~/lib/python/ is the path you set above. Save it, and logout and back in again.

You should now be able to see that it variable is set, simply by typing $PYTHONPATH

Actions: Trackbacks Disabled, Permalink,