Skip to content

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 Rocky 8 clusters is /usr/bin/python3:

[unid@cluster]$ python3
Python 3.6.8 (default, Nov  9 2021, 14:44:26) 
[GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] on linux
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 version of Python actively on our Rocky 8 systems:

  • Python 3.10.3  (Python 3)

This version also contains quite a few external modules to perform scientific computing (please see below).

The latter Python stacks supports 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

 

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

module load python/3.10.3

 

Note that there is still a version of Python 2 available (for legacy reaons): /usr/bin/python2

Integrated development environment

There are a number of IDEs for Python development, some of which are marginally stable. We recommend using the 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 FastX 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 3.10.3:
    module load python/3.10.3
    pip list

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

External documentation

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

Last Updated: 6/4/24