Python

Python, a programming language, is available without modules.

On request of our users, we can install newer version, which are available using the module command.

Type

module avail python

to see which Python versions are installed.

Usage

  • Load the python module, which give you the newest version:
module load python
  • Load a specific version, eg 3.1.2:
module load python/3.1.2

Note: the name of the program depends on the version: for version 3.x.y the name is

python3

Installing python packages

Here follows a recipe to install python packages:

As an example we demonstrate how to install the package `Gnuplot`.

Many packages are already installed, so try that first:

  • login to lisa
  • If you need the newest installed version:
module load python
  • Start python:
python
  • Try to import Gnuplot:
import Gnuplot Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Gnuplot

So, package `Gnuplot` is not installed. To install it:

  • login to lisa
  • If you need the newest installed version of python:
module load python
  • Locate the package and download it to lisa:
wget http://sourceforge.net/projects/gnuplot-py/files/Gnuplot-py/1.8/\
 gnuplot-py-1.8.tar.gz/download 
mv download gnuplot-py-1.8.tar.gz
  • extract the package:
tar xzvf gnuplot-py-1.8.tar.gz
  • change the directory:
cd gnuplot-py-1.8
  • Install the package:
python setup.py install --home=$HOME/pythonpackages

That is nearly all. The package is installed now in the directory 'pythonpackages' in your home directory. We advise to install all your python packages in this directory.

  • Now, you must tell python where to look for installed packages:
export PYTHONPATH=$HOME/pythonpackages/lib/python:$PYTHONPATH
  • Test if the package can be used:
python
  >>> import Gnuplot
  >>>

So, the installation was successful.

Installing python packages using easy_install

The recipe to install python packages using easy_install is slightly different. As an example we demonstrate how to install the package `nose`.

  • Define PYTHONPATH:
export PYTHONPATH=$HOME/pythonpackages/lib/python2.6/site-packages:$PYTHONPATH
# python2.6: depends on the version of python that is running.
# for version 2.6.xxx it is python2.6
# for version 2.7.xxx it is python2.7
# and so on
# The command 
# python --version
# prints the version number
  • Create directory for packages:
mkdir -p $HOME/pythonpackages/lib/python2.6/site-packages
  • Install the package:
easy_install --prefix=$HOME/pythonpackages nose
  • Test if the package can be used:
python
 >>> import nose 
 >>>

So, the installation was successful.