Skip to content

Using the Python interpreter

The Python interpreter running on Arrhenius

Learning outcomes

  • Practice using the documentation of your HPC cluster
  • To be able to login to your HPC cluster
  • To be able to load Python
  • To be able to run a minimal Python program
For teachers

Teaching goals are:

  • Learners have used the documentation of their HPC cluster
  • Learners have used the Python interpreter
  • Learners have loaded Python

Other goals are:

  • Verify that learners indeed have learned how to login
  • Verify that learners indeed have learned how to use the module system

Prior and feedback question:

  • On an HPC cluster, what are software modules?
  • On an HPC cluster, which problem do software modules solve?
  • On an HPC cluster, why don't we let users install all software themselves?
  • What does it mean that Python is an interpreted language?
  • What is an interpreter?

Notes:

  • For those that use Bianca, it may take some time to get a login node. Encourage those to try Pelle while waiting

What are software modules?

A software module is an installed pieces of software of a specific version.

Here is an example to load Python version 3.12.7 on the Bianca HPC cluster:

module load python/3.12.7

Why software modules are important

Software modules allows users of any HPC cluster to activate their favorite software of any version. This helps to assure reproducible research.

Why the Python interpreter is important

flowchart TD
  a_letter[A letter to do something]
  employee[Employee]
  something_done[Something is done]
  a_letter --> employee --> something_done

  code[Code]
  interpreter[Interpreter]
  machine_code[Machine code]
  code --> interpreter --> machine_code

The Python interpreter is the program that lets your Python code do something. It is at the heart of using Python: without it, you cannot do Python programming.

Exercises

Enjoy a video?

You can find a video with solutions to these exercises:

HPC Cluster Login method YouTube video
Arrhenius HPC ThinLinc Video
Bianca SSH Video
COSMOS SSH Video
Dardel SSH Video
Kebnekaise SSH Video
LUMI SSH Video
Pelle SSH Video

To develop code in Python on your HPC clusters, one needs to:

  • Login to that HPC cluster, to be able to work on it
  • Load the Python module, to be using the right Python interpreter and environment
  • Use the Python interpreter, to run Python code

Luckily, the documentation of your HPC center should allow you to do this by yourself!

These exercises will ensure you are able to run a minimal Python program.

How difficult will this exercise be?

The difficulty of these exercises depends on your HPC cluster:

HPC cluster name Need VPN? Need SSH keys? Need 2FA? Documentation Difficulty
Arrhenius HPC No No Yes Excellent Medium
Bianca Yes No Yes Excellent Medium
COSMOS No No Yes Good Easy
Dardel No Yes No Minimal Medium
LUMI No Yes No Reasonable Medium
Kebnekaise No No No Good Easy
Pelle No No No Excellent Easy

Demonstration

Before doing the exercises, a teacher will speedrun through the exercises.

Exercise 0: be assigned a Zoom room

We will use breakout rooms, as this is best for interaction and learning. However, some prefer to work alone. In this course, we allow for both.

For a quick process, we follow the following procedure:

flowchart TD

  prefer_work_together(Prefer to work together?)
  say_yes[Say yes]
  say_no[Say no]

  prefer_work_together --> |Yes| say_yes
  prefer_work_together --> |No| say_no

How to state yes/no

You will be ruthlessly moved to a breakout room when possible.

Good luck and enjoy!

Exercise 1: login to your HPC cluster

Login to your favorite HPC cluster. This should be easy, as this is a prerequisite for this course.

Exercise 2: load the Python module

Got to the user documentation for your favorite HPC cluster:

HPC cluster User documentation
Arrhenius User documentation
Bianca User documentation
COSMOS User documentation
Dardel User documentation
Kebnekaise User documentation
LUMI User documentation
Pelle User documentation
Answer

From the documentation of your center, searching for, for example, 'Python module', you will find information on how to load the Python module.

HPC Cluster Documentation
Arrhenius HPC Documentation
Bianca Documentation
COSMOS Documentation
Dardel ⚠ Documentation and more documentation
Kebnekaise Documentation
LUMI Documentation
Pelle Documentation
  • Using that documentation, load a Python software module of the version indicated in the table below.
HPC Cluster Python version
Arrhenius HPC 3.13.5-bundle-SciPy-2025.07-mpi4py-4.1.0-gcc-2025b-eb
Bianca 3.12.7
COSMOS 3.11.5
Dardel 3.12.3
Kebnekaise 3.11.3
LUMI 3.11.7
Pelle 3.11.5-GCCcore-13.2.0
Answer

HPC Cluster Documentation
Arrhenius HPC module load Python/3.13.5-bundle-SciPy-2025.07-mpi4py-4.1.0-gcc-2025b-eb
Bianca module load python/3.12.7
COSMOS module load GCCcore/13.2.0 Python/3.11.5
Dardel module load PDC python/3.12.3
Kebnekaise module load GCC/12.3.0 Python/3.11.3
LUMI module load cray-python/3.11.7
Pelle module load Python/3.13.5-GCCcore-14.3.0

Exercise 3: start the Python interpreter

Answer

From the documentation of your center, searching for, for example, 'Python' or 'Python interpreter', you may find information on how to start the Python interpreter.

HPC Cluster Documentation Solution
Arrhenius HPC Documentation python
Bianca Documentation python
COSMOS ⚠ python
Dardel ⚠ Documentation python
Kebnekaise ⚠ python
LUMI ⚠ Documentation python
Pelle Documentation python
  • ⚠ for this specific question means that the documentation does not answer this (or the answer is hiding in more complicated examples). You may find this an acceptable omission or you may not. You are encouraged to contact your HPC center to help them help you better
  • Start the Python interpreter
Answer

HPC Cluster Solution
Arrhenius python
Bianca python
COSMOS python
Dardel python3
Kebnekaise python
LUMI python
Pelle python
Cannot get this to work?

If there is no time to get this fixed during the course, you can also use Python on your local computer.

Exercise 4: run a 'Hello world' program

Copy-paste the following code to the Python interpreter:

print('Hello, world!')

Press enter.

How does that look like?

Answer

Your output will look similar to this:

$ python
Python 3.12.3 (main, Nov  6 2024, 18:32:19) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Hello, world!')
Hello, world!
>>>

Congratulations, you've just run a 'Hello world' program 👍

Done?

Go the the main room and start working on, for example, the next session. When around two thirds are in the main room, we move on to the next session.