Installing a Python package locally on a linux box

Created 8 years ago by Matt,
Last updated February 27th 2018, 1:51:55 pm

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

Comments

  1. Just a comment on your gunzipping of the file. You know tar can handle (at least) gzip and bzip itself. tar xzf matplotlib-1.0.1.tar.gz - Eoin on Mon Jun 20 2011 09:51:39 GMT+0000 (UTC)