Python is a general purpose programming and scripting language. There are a large number of additional modules/libraries available for a wide range of purposes, including many for numerical and scientific computing.


Python is installed for all Flux services and typically several versions are available. We also install a few additional libraries that have proven to be of general use and widely used. See Python standard libraries for the list.

In addition to the version of Python that is compiled specifically for Flux, we also have available a precompiled version that bundles a large number of libraries, which can be very convenient. This is the Enthought Python Distribution (EPD). For more details, see Python distributions. You should only use one of EPD or one of our Python modules on Flux, not both, as they both provide the python command.

The operating system also comes with a version of Python. Sometimes it is appropriate to use that, but we generally recommend that you use one of our Python modules or one of the EPD modules.

Accessing python

To see which versions of Python are currently available on Flux, use

$ module available python

To see which versions of the EPD are available, use

$ module available epd

To use the python or epd modules, use

$ module load python/2.7.5


$ module load epd

Running Python interactively

Python can be run in “true” interactive mode simply with

$ python

The prompt changes to Python’s >>> prompt. To exit, you can use either the Python quit() function, or Ctrl-D at the triple-chevron prompt.

Running Python in batch mode

More often, you will have a Python script to run, in which case you provide the filename of the script as an argument. Python scripts often have the .py extension, but it is not required. For example, if you have this line in a file called

print "Hello, world."

then running it would look like the following transcript.

$ python
Hello, world.

Most Python use will be with programs or scripts, typically stored in files with a .py extension. When Python runs a script, it will create a compiled version, which will have a .pyc extension; do not try to run those directly.

You can also create a Python script that can be run as a command. For example, create a file called python-example that contains the lines

#!/usr/bin/env python

import os
name = os.getenv('USER')
dir  = os.getcwd()

print "%s ran this from %s" % (name, dir)

Set the file permissions so it is runnable as a command using

$ chmod a+x python-example

Finally, run it using


(or use the full path to it; e.g., /home/grundoon/python-example).

Running Python from PBS

Running Python from a PBS script is just like running it in batch, except that you put the python command into a file that is submitted to PBS. For this example, call it test.pbs. (For more information on PBS, see the PBS web page.) Here is an example PBS script to run the script with Python. Note that most Python programs can only use one processor, so you should not specify either nodes= or procs= a number greater than 1 unless you are sure that your program can use them.

####  PBS preamble
#PBS -N python_test
#PBS -m abe

#PBS -l nodes=1:ppn=1,mem=1gb
#PBS -j oe

#PBS -A example_flux
#PBS -l qos=flux
#PBS -q flux

####  End PBS preamble
#  Include the next three lines always
if [ "x${PBS_NODEFILE}" != "x" ] ; then
   cat $PBS_NODEFILE   # contains a list of the CPUs you were using if run with PBS
#  Put your job commands after this line