Go to the U of M home page
School of Physics & Astronomy
Physics & Astronomy Wiki

computing:department:unix:development:python

python on Physics linux systems

Python is one of the most used interpreted languages for data analysis, competing directly with long-established commercial packages like Matlab or IDL.

python versions on Scientific Linux

Different versions of the OS come with different versions of python.

  • SL5 comes by default with python 2.4, but python 2.6 is also available (called as /usr/bin/python26).
  • SL6 comes by default with python 2.6, but 2.7 and 3.3 are available via RedHat's software collections

Scientific packages

The most popular are

  • Scipy - The main scientific library
  • Numpy - Arrays manipulation library
  • Matplotlib - 2D (and basic 3D) plotting library
  • IPython - An advanced interactive console

All of these should be available by default on our systems (though see our notes below on how to install newer versions for yourself if wanted).

A wide variety of Astronomy-related python packages are installed as part of Ureka

installing additional packages

You might find that some python packages you need are not available pre-packaged for our linux distribution, or the available version might be too old. There are a couple of ways you can handle this - first here is the simplest, installing the modules within your home directory (then read about “virtualenv” below for a cleaner solution).

To install a python module in your user space, download the tarball, unzip it, cd into the directory and run:

python setup.py install --prefix=/path/to/your/place

The installer will create a subdirectory named lib, or lib64 under the directory above. These lib* dirs will have a directory named python, or python2.6 (for example), and those will have a subdirectory named site-packages. Add all paths to these site-packages subdirectories in your PYTHONPATH environment variable. Some packages may also create a bin directory that needs to be added to PATH.

virtualenv

The virtualenv kit provides the ability to create virtual Python environments that do not interfere with either each other, or the main Python installation. If you install virtualenv before you begin coding then you can get into the habit of using it to create completely clean Python environments for each project. virtualenv should be installed on all SL6 Linux machines.

To create a new virtual environment (named “py_phys” in this example), run

virtualenv py_phys

This will create a directory named py_phys in the current working directory. You can also specify a full path, e.g. virtualenv /tmp/py_phys

To activate the new environment, use

. py_phys/bin/activate

Once in the new environment, you can add packages using the pip command, eg:

pip install packageName

Group or project software installs

Often a set of software will be used by an entire group rather than just one individual. We can set up specific areas for you to manage shared software, rather than within a home directory.

computing/department/unix/development/python.txt · Last modified: 2015/08/13 17:47 by allan