You are here

Python

Table of Contents

Introduction

Python is an interactive, object-oriented, extensible programming language. There is a Python distribution on each WestGrid system, which was installed as part of the basic operating system environment. However, more recent versions are typically also available. To select one of these updated versions, one typically will have to use a variation on the  module load python command, as indicated in the usage instructions on the Python Software Versions page.  The use of modules to configure software is explained on a separate page.  Please note that these modules are completely unrelated to the Python modules discussed below.

Installed modules

Much of the utility of Python comes from modules that have been installed to extend the base functionality. Some of these modules (NumPy, SciPy and matplotlib, for examples) are available on most WestGrid systems, whereas others have been installed in response to requests on specific systems.  It would be expensive to maintain a complete and up-to-date list of modules available for each version of Python on all the WestGrid systems.  Instead, in this section, we discuss commands one can use to determine which modules have been installed.  The specific commands depend on which Python distribution is being used and the level of detail that is required.  Some examples are given here.

Module list with Python help (all systems)

With all Python distributions, the following commands will give a detailed list of modules that are available, but, does not show the version number:

python
help('modules')

Alternatively, one can use the pydoc command (at the Linux shell prompt, not at the Python prompt) to avoid a bit of typing:

pydoc modules

Once the name of a particular installed module is known, the Python help command can also be used to show any associated documentation for that module, which often shows the version number.  Be sure to include the module name in single quotes when using help.  For example, at the Python prompt:

help('mpi4py')

Alternatively, one can call up the documentation from the Linux shell prompt with the pydoc command:

pydoc mpi4py

Version numbers are also available for many modules (but, not all) using the __version__ attribute.  You must import the module before issuing the associated version command.  Note the module name is followed by a period, with two underscores before and two underscores after the word version.

import mpi4py
mpi4py.__version__

Module list with pip (Bugaboo, Breezy, Grex, Jasper, Lattice, Parallel)

With some Python distributions, the command

pip list

can be used to get the names of installed packages along with their version numbers.  However, there are some limitations with using pip.  Some installed modules may not show in the pip output and the pip command itself may not be available with some Python installations.  With some older versions of pip, the list option is not available, but,

pip freeze

can be used instead to give similar output.

Also, you have to be careful that the pip command you are using is associated with the Python installation in which you are interested.  You can check with

pip --version

to see which installation is associated with the current pip command.

With Python 3.x distributions there is a pip3 command that can be used in a similar manner to pip.

pip3 list

Module list with conda for Anaconda Python (Grex, Jasper)

For the Anaconda Python installations on Grex, the conda command can be used at the Linux shell prompt to get a list of installed modules, along with version numbers:

conda list

For More Information

Updates:

2014-03-18 - Added section on commands to determine which modules have been installed.

2014-03-21 - Added pip3 reference.