Python

The Python programming language is provided on all nodes of the Lovelace. Multiple versions of the Python Interpreter are provided. In fact, for a specific version of Python (e.g. Python 3.11), multiple versions of the same Interpreter are provided. This document details how users should load or install packages on the cluster.

Setting up a Python Environment with Modules

A selection of Python Packages are available through the modules framework described in ../user-guide/modules. To see a selection of the available Python packages, run:

module avail

Many Python packages are hidden as they are usually not directly loaded by users but rather as dependencies of other Python packages. It is possible show these packages but this view is not reccomended for users due to the length of the output. To see all available packages, run the command below.

module --show_hidden avail

Modules for Python packages are named with the prefix py-. Such modules support a specific version of Python. You can tell which packages a module supports by looking at its suffix. If there is no suffix, the module supports the recommended version of Python selected by the HPC Admin team, currently Python 3.11. If there is a suffix, such as -py3.13, the module supports only the version indicated in the suffix. Some examples of the naming convention are given below:

  • py-numpy provides the NumPy Python Package for the recommended version of Python (currently Python 3.11)

  • py-pip provides the Pip Python Package for the recommended version of Python (currently Python 3.11)

  • py-pip-py3.13 provides the Pip Python Package for Python 3.13

To load only the recommended version of python itself, simply run:

module load python

Setting up a Python Environment without Modules

It is also possible to set up a python environment without modules. The following versions of Python are provided outsite of modules:

  • Python 3.12

  • Python 3.11

  • Python 3.9 (not reccomended)

  • Python 3.6 (not recommended)

Users can also create Virtual Environments with these Python Versions. For example to set up SciPy in a Virtual Environment without using Modules with Python 3.12:

[apraveen@uop-hpc ~]$ python3.12 -m venv scipy
[apraveen@uop-hpc ~]$ . scipy/bin/activate
(scipy) [apraveen@uop-hpc ~]$ pip install scipy
Collecting scipy
  Obtaining dependency information for scipy from https://files.pythonhosted.org/packages/b0/3c/0de11ca154e24a57b579fb648151d901326d3102115bc4f9a7a86526ce54/scipy-1.15.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata
  Downloading scipy-1.15.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.0/62.0 kB 3.8 MB/s eta 0:00:00
Collecting numpy<2.5,>=1.23.5 (from scipy)
   Obtaining dependency information for numpy<2.5,>=1.23.5 from https://files.pythonhosted.org/packages/5b/73/65d2f0b698df1731e851e3295eb29a5ab8aa06f763f7e4188647a809578d/numpy-2.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata
  Downloading numpy-2.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.0/62.0 kB 11.3 MB/s eta 0:00:00
Downloading scipy-1.15.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 40.2/40.2 MB 121.8 MB/s eta 0:00:00
Downloading numpy-2.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 16.1/16.1 MB 157.2 MB/s eta 0:00:00
Installing collected packages: numpy, scipy
Successfully installed numpy-2.2.2 scipy-1.15.1

[notice] A new release of pip is available: 23.2.1 -> 25.0
[notice] To update, run: pip install --upgrade pip
(scipy) [apraveen@uop-hpc ~]$ python3
Python 3.12.1 (main, Feb 21 2024, 10:25:11) [GCC 8.5.0 20210514 (Red Hat 8.5.0-21)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy.sparse
>>> scipy.sparse.eye(3)
<DIAgonal sparse matrix of dtype 'float64'
        with 3 stored elements (1 diagonals) and shape (3, 3)>

Conda

A conda module is also provided. To use it, simply load the module:

module load conda