If you use a High-Performance Computing (HPC) cluster, you have probably run into this exact scenario: you write a Python script, try to run it, and immediately get hit with:
Python
ModuleNotFoundError: No module named 'nibabel'
You check the cluster documentation, and the admins swear the package is installed. So why can’t Python find it?
Unlike your personal laptop, HPC clusters use environment modules (like Lmod) to manage hundreds of conflicting software versions. Software isn’t installed globally; it stays hidden until you explicitly load it. Here is how to track down missing Python packages and load them properly.
The “Import Name” vs. “Package Name” Trap
Before searching the cluster, make sure you are looking for the software’s actual name, not just its Python import shortcut. Lmod tracks installation packages, not Python syntax.
A classic example is skimage. If your script fails on import skimage, searching the cluster for “skimage” will return an error. You have to search for the official package name: scikit-image.
The Lmod Workflow
Here is the exact process to find and load the packages your script needs.
1.Search the entire module system:
Find out if the package exists.
Use the module spider command. Unlike module avail (which only shows what is compatible with your currently loaded modules), spider searches everything installed on the cluster.
Bash
module spider nibabel
If it is installed, Lmod will list the available versions. You might notice an (E) next to the version name. This means the package is an Extension—it is bundled inside a larger “parent” module, and you cannot load it directly.
2.Find the required parent module:Ask Lmod for instructions.
To figure out how to access that extension, run the spider command again, but this time attach the specific version number you want to use.
Bash
module spider nibabel/5.3.2
Lmod will output exactly which module you need to load. For example, it might say: This extension is provided by… NiBabel/5.3.2-gfbf-2023b.
3.Load the environment:
Activate the software.
Now, load the specific parent module Lmod gave you in the previous step.
Bash
module load NiBabel/5.3.2-gfbf-2023b
Pro-tip: Pay attention to the toolchain (like 2023b or GCC-12.3.0). If your cluster prints a warning that a specific toolchain is scheduled for deprecation, try to load a newer version so your scripts don’t break in the future.
4.Run your script:
Execute with the correct environment.
Now that the correct module is loaded, Python’s environment paths are updated. Your script will now successfully find the package.
Bash
python my_script.py
What if module spider finds nothing?
If module spider scikit-image or module spider nibabel returns no results, the package genuinely is not installed as a module on your cluster. In that case, you have two options:
- Search for larger bundles (like
module spider SciPy-bundle), which often contain dozens of common data science packages. - Create a Python virtual environment (
venvorconda) and install the package yourself usingpip.
Discover more from Knowledge sparks
Subscribe to get the latest posts sent to your email.