Python
Python is a high-level, interpreted programming language popular in scientific computing for its readability and its enormous ecosystem of third-party libraries — NumPy, Pandas, scikit-learn, PyTorch, TensorFlow, and many more. This page describes how to use Python on Anunna: the provided modules, how to manage your own packages with virtual environments or Miniforge, and how to expose an environment as a Jupyter kernel.
Modules
Anunna provides one Python version per module bucket, plus bundle modules that carry a curated set of common extensions. Load a bucket, then the Python module:
- 2023:
Python/3.11.3 - 2024:
Python/3.12.3
module load 2024
module load Python/3.12.3
The bundle module Python-bundle-PyPI adds many frequently-used packages on top of the base interpreter. Use module key <package> to find which bundle contains a package you need (see searching modules by keyword).
For packages not in a module, the two recommended routes are a virtual environment built on a Python module (below), or Miniforge for a self-contained conda/mamba setup. The use of Anaconda is discouraged on Anunna — its default channels carry licensing restrictions and the full distribution is heavy; Miniforge is the lighter, unrestricted alternative.
Virtual environments
A virtual environment is a self-contained directory holding a specific Python and its packages, so one project's dependencies cannot clash with another's. Python's built-in venv module is the simplest way to make one on top of a Python module.
First load the Python version you want:
module load 2024
module load Python/3.12.3
Then create the environment in a location of your choosing. The example uses $myNobackup/PythonEnv — $myNobackup is your Lustre nobackup location, set in your ~/.bash_aliases (see Aliases and local variables). Keeping environments on Lustre rather than your home directory avoids filling your home quota, and the nobackup tier is the right choice because an environment can always be recreated from scratch and so does not need backing up.
python -m venv $myNobackup/PythonEnv/my_env
Activate it whenever you want to use it:
source $myNobackup/PythonEnv/my_env/bin/activate
Once active, the environment name appears as a prefix in your prompt:
(my_env) user001@login200:~$
Install packages with pip while the environment is active; they go into the environment, not your home directory:
pip install -U numpy pandas matplotlib
Leave the environment with deactivate.
Miniforge (conda / mamba)
Miniforge is a minimal installer that gives you the conda and mamba package managers preconfigured to use the community conda-forge channel. mamba is a fast drop-in replacement for conda. This is the recommended way to use conda-style environments on Anunna; it avoids Anaconda's licensing restrictions.
Download and run the installer, pointing it at a location with room (your Lustre nobackup space, not your home directory):
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
bash Miniforge3-Linux-x86_64.sh -b -p $myNobackup/miniforge3
Do not run conda init on Anunna — it writes startup code into your ~/.bashrc that runs on every login and can interfere with the module system. Instead, activate Miniforge only when you need it:
source $myNobackup/miniforge3/bin/activate
Then create and use environments with mamba:
mamba create -n myenv python=3.12 numpy pandas
mamba activate myenv
Jupyter kernels
To use one of your environments inside Jupyter, register it as a kernel.
From a virtual environment
A venv kernel needs a wrapper script, because the kernel is launched without your normal shell environment and so cannot load modules by itself. First, with the environment active, install ipykernel and generate the kernel:
module load 2024
module load Python/3.12.3
source $myNobackup/PythonEnv/my_env/bin/activate
pip install ipykernel
python -m ipykernel install --user --name=my_env_kernel
The kernel is written to ~/.local/share/jupyter/kernels/, which Jupyter watches. On its own it will not work, because it cannot find the modules — so write a wrapper script that loads them. Save this as, for example, $HOME/wrap.sh:
#!/bin/bash -l
module reset
module load 2024
module load Python/3.12.3
exec $myNobackup/PythonEnv/my_env/bin/python -m ipykernel_launcher "$@"
The #!/bin/bash -l line starts a login shell, which loads Lmod and sources your ~/.bash_aliases (so $myNobackup is defined). Make the wrapper executable with chmod +x $HOME/wrap.sh.
Finally point the kernel at the wrapper by editing ~/.local/share/jupyter/kernels/my_env_kernel/kernel.json:
{
"argv": [
"/home/WUR/user001/wrap.sh",
"-f",
"{connection_file}"
],
"display_name": "Python my_env",
"language": "python",
"metadata": {
"debugger": true
}
}
The only difference from a plain kernel file is that argv points at the wrapper script instead of the Python executable directly.
From a conda / mamba environment
A conda or mamba environment is simpler, because the environment is self-contained. With Miniforge active and your environment created, install ipykernel into it and register the kernel:
mamba create -y -n kernel_test python=3 ipykernel
mamba activate kernel_test
python -m ipykernel install --user --name kernel_test
To remove the kernel and environment again:
jupyter kernelspec uninstall kernel_test
mamba deactivate
mamba remove -y -n kernel_test --all