You are here:

Python

Python is an interpreted programming language that is relatively easy to learn yet powerful and extensible. A library of thousands of packages makes it suitable for scientific applications and its user base, extensive documentation, and ease of development make it a good choice for experimenting and prototyping.

Python

The default (system) version of Python on our CentOS 7 clusters is /usr/bin/python:

[unid@cluster]$ python
Python 2.7.5 (default, Sep 15 2016, 22:37:39)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

This Python version is older, may not include packages that one may need, and the included packages may not have optimal performance. To get newer Python stack, there are two options.

The FIRST option, which we STRONGLY recommend (due the complexities of maintaining a central Python distribution), is for everyone to install their own Miniconda or Anaconda, as described in our User installed Python article. The latest versions of Anaconda2 & Anaconda3 are also avaiable within CHPC's /uufs tree.

The SECOND option is to use one of the Python stacks installed by the CHPC and described in detail below. These Python stacks are good if one's Python code does not require many external modules or are not provided by Anaconda.

CHPC supports the following versions of Python actively on our CentOS 7 systems:

  • Python 2.7.11  (Python 2)
  • Python 3.5.2  (Python 3)
  • Python 3.6.3 (Python 3)

These versions also contain quite a few external modules to perform scientific computing (please see below).

All of the latter Python stacks support OpenMP threading. The OpenMP threading has been switched off by default. To invoke the threading (e.g. in a SLURM script) you need to set the environmental variable OMP_NUM_THREADS to x ( x being a number <= #cores on the machine)

export OMP_NUM_THREADS=x  # Bash
setenv OMP_NUM_THREADS x # Tcsh

In order to use Python 2.7.11 on our clusters/desktop, you need to invoke the following command:

module load python/2.7.11

 If you would like to use Python 3.5.2, you need to execute the following command:

module load python/3.5.2

The Python 3.6.3 environment can be loaded in a similar fashion:

module load python/3.6.3

 

Integrated development environment

There are a number of IDEs for Python development, some of which are marginally stable. We recommend using free PyCharm Community. As it features automatic updates, we require users to download and install PyCharm in their home directory. As IDE requires graphical connection to our servers, one needs to run FastX2 or other means of X window connection in order to use PyCharm.

Another good IDE is Spyder, which is installed the easiest with Anaconda. Therefore, if one prefers Spyder, we recommend User installed Python.

Back to PyCharm, after installation, one can add the PyCharm bin directory to the PATH:

setenv PATH "$HOME/pycharm/bin:$PATH" - for tcsh
export PATH=$HOME/pycharm/bin:$PATH" - for bash

or, even better, create custom module, e.g. create a file $HOME/mymodules/pycharm/version.lua:

-- -*- lua -*-
help(
[[
This module loads the env. variables
for PyCharm (v. 2016.1.4)
]])
whatis("Name: PyCharm ")
whatis("Version: 2016.1.4 ")
whatis("Category: IDE ")
whatis("Keywords: IDE, Python ")
whatis("Installed on 06/03/2016")
prepend_path("PATH","/uufs/chpc.utah.edu/common/home/UNID/pycharm/2016.1.4/bin")

and then adding the modules directory to as a custom module and load the module and run PyCharm:

module use $HOME/mymodules
module load pycharm
pycharm.sh

Installed packages

Each of the aforementioned python distribution has an array of packages installed. You can list all the currently installed packages, by typing:

  • python 2.7.11:
    module load python/2.7.11
    pip list
  • python 3.5.2:
    module load python/3.5.2
    pip list
  • python 3.6.3:
    module load python/3.6,3
    pip list

We already suggested (see above) the Anaconda/Miniconda environment if users want to install packages in their own environment.

An alternative option is to use the Python Virtual Environment (PyVENV). The installation of a derived Python Distribution using the PyVENV allows you to use those packages (e.g. NumPy, SciPy, etc.) that are installed within the general (CHPC) distribution and to install/use specific packages that are only available in the new (derived) environment. For more info, please have a look at our Python Virtual Environment page.

External documentation

Below, you can find the links to the documentation of some important packages/sites.

Last Updated: 3/15/19