Python

Python, a programming language, is available without modules. However, this version might be too old or miss certain modules. Therefore, we have newer versions available. They can be accessed using the module command.

Type

module avail python

to see which Python versions are installed.

Usage

  • Load the python module, which gives you the default version:
module load python
  • Load a specific version, eg 3.4.2:
module load python/3.4.2

(note that Python 3 is used through the "python3" executable)

Installed packages

The following packages are installed for Python 2.7.9:

argparse (1.3.0)
bitarray (0.8.1)
bzr (2.6.0)
configobj (5.0.6)
Cython (0.21.2)
docutils (0.12)
fastlmm (0.2.4)
ipython (2.3.1)
Jinja2 (2.7.3)
libmagic (1.0)
MarkupSafe (0.23)
matplotlib (1.4.2)
melview (1.0.1)
mock (1.0.1)
mpi4py (1.3.1)
nibabel (2.0.0)
nose (1.3.4)
numexpr (2.4)
numpy (1.9.1)
pandas (0.15.2)
patsy (0.3.0)
Pillow (2.7.0)
pip (1.5.6)
pycrypto (2.6.1)
pyface (4.4.0)
Pygments (2.0.1)
pyparsing (2.0.3)
PySide (1.2.2)
pysnptools (0.2.3)
pysqlite (2.6.3)
python-dateutil (2.3)
pytz (2014.10)
scipy (0.14.1)
setuptools (7.0)
six (1.9.0)
Sphinx (1.2.3)
statsmodels (0.6.1)
traits (4.5.0)
traitsui (4.4.0)
wsgiref (0.1.2)

The following packages are installed for Python 3.4.2:

Cython (0.21.2)
docutils (0.12)
ipython (2.3.1)
Jinja2 (2.7.3)
libmagic (1.0)
MarkupSafe (0.23)
matplotlib (1.4.2)
mock (1.0.1)
mpi4py (1.3.1)
nose (1.3.4)
numpy (1.9.1)
pandas (0.15.2)
patsy (0.3.0)
Pillow (2.7.0)
pip (1.5.6)
pycrypto (2.6.1)
Pygments (2.0.1)
pyparsing (2.0.3)
python-dateutil (2.3)
pytz (2014.10)
scipy (0.14.1)
setuptools (2.1)
six (1.9.0)
Sphinx (1.2.3)
statsmodels (0.6.1)

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.