Python is available on both Snellius without loading any modules. However, this version (2.7.5 or 2.7.16) might be too old or miss certain modules. Therefore, we have newer versions available. They can be accessed using the module command.

Load one of the software environments first. The currently active ones are 2022 and 2021 on Snellius.

module load 2022

You can then type

module avail Python

to see which Python versions are installed (e.g. 3.9.5 for the 2021 software stack).

Usage

You can load a specific version of Python by issuying the module load command with the version of Python you want.

module load Python/2.7.18-GCCcore-11.3.0-bare
#or
module load Python/3.10.4-GCCcore-11.3.0

You can check which python version was loaded by issuing the command

module list

Scipy

The most commonly used scientific python packages (numpy, scipy, pandas) can also be loaded via the SciPy-bundle module. i.e.

module avail SciPy-bundle
module load SciPy-bundle/2022.05-foss-2022a

NOTE

If you load the python module (module load Python) before you load the SciPy-bundle module you will likely get a conflict between python modules. In order to have no conflicts between python module files it is best to only load the module you need. For example if you need the python packages in the SciPy-bundle you should only load SciPy-bundle as it also includes python.

Loading the SciPy-bundle:

module purge 
module load 2021
module load SciPy-bundle/2021.05-foss-2021a

You can always list the available python packages via

pip list

Anaconda

Like the Scipy-bundle module an Anaconda module is also provide to give you access to the python packages available to those distributions and can be loaded via:

module load 2021
module load Anaconda3/2021.05

Miniconda is provided as well

module load 2021
module load Miniconda3/4.9.2

If you think we missed an important package, please request its installation by contacting our Service Desk.

Installing python packages

If you require a python package that this not installed on the system (or is not included in the Scipy-bundle or Anaconda modules) you can always install a python package in your home. Here we give an example on how to install a python package for the default python distribution which can be loaded as a module.

As an example we demonstrate how to install the package `svgutils`. This package is not included with the default python module (what is loaded when you "module load Python").

Ok lets start from scratch.

  • Login to Snellius. (if you are already logged in, you should only have the default modules loaded. So either logout and log back in, or issue a module purge command.)
  • Load the default python module 
module load 2021
module load Python/3.9.5-GCCcore-10.3.0
  • Start python:
python
  • Try to import svgutils:
>>> import svgutils
Traceback (most recent call last):
File "", line 1, in 
ImportError: No module named svgutils

So, package `svgutils` is not installed. In order to install it:

  • exit the python interpreter
>>> exit()
  • Install the package via pip with the command
pip install --user svgutils

That is all. The package is now installed in the directory '.local/lib/python3.9' in your home directory. Note that different python versions will install in different subdirectories. We advise to install all your python packages in this directory. Note that the OS-installation of python (note the modules) does not have the pip command.

  • Test if the package can be used:
python
>>> import svgutils
>>>

The installation was successful!

Though this example was for the default python module using pip, you can apply the same principles with the other available python modules. You can as well create a virtual environment using conda for the Anaconda distribution of python. Please read more here https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/

More information

  • No labels