Python#
Python is a dynamic very popular programming language. Python is an open source software. It has wide applications in many HPC softwares and related workflow. Python is well known for having a broad libraries and big community around the world.
Python at NHPCC#
To use python in its interactive mode, you can simply load the python module and run it:
ml Python
python
to see its interactive session as below:
Python 3.10.8 (main, Jul 16 2023, 23:15:21) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Using Python in batch scripts#
It is also possible to load Python module in a job script. The script could be written as:
#!/bin/bash
#SBATCH ...
#SBATCH ...
#SBATCH ...
ml purge
ml load Python
./hello_world.py
Using Anaconda distribution#
You can use Anaconda python distribution by loading its module:
ml Anaconda3
To check the python path, run:
which python
Installing packages#
Conda#
Miniconda#
Mamba#
Mamba is a Python-based CLI conceived as a drop-in replacement for conda, offering higher speed and more reliable environment solutions
As an example, we are going to install the astropy package. We first load the Mamba
module and then make an environment with an arbitrary name:
ml Mamba
mamba create -n ENV_NAME
Now, we should activate it and then install the desired package(s):
mamba activate ENV_NAME
mamba install -c conda-forge astropy
After installation termination, you can list all the environments:
mamba env list
To remove an environment with all its packages, do:
mamba env remove -n ENV_NAME
You can export an environment, i.e. make a file that contains all the installed packages with their versions:
mamba env export -n ENV_NAME > ENV_NAME.yaml
This file can be used for cloning this environment in the future. This is very helpful for reproducibility of your works.
mamba env create --file ENV_NAME.yaml
Finally, you can deactivate your environment:
mamba deactivate