Conda & Python
For Python and environments, we offer the modules
miniforge3
- CPython
The environment base
is installed system-wide and cannot be modified.
The old module anaconda3
is no longer supported. Please switch to another module.
We discourage users from using the module miniconda3
because the “default” channel requires a paid license for more than 200 employees (including doctoral research positions) and outside of class room usage.
You use this module at your own risk!
Loading the module and preparing an environment
We recommend NOT to use conda init
. This way, the .bashrc
is not updated and the environment is not loaded at each login, reducing unnecessary load on the systems and making your login much faster.
In order to use Python and Conda environments, load the module miniforge3
and create an environment.
We strongly suggest you create this environment on the scratch filesystem using the prefix option.
You can use the environment variable $WORK
that always points to your personal scratch directory.
This example loads the module, creates a new environment called myenv
on the scratch filesystem using the variable $WORK
, loads python3.12, and activates it using the source command.
module load miniforge3
conda create --prefix $WORK/myenv python=3.12
source activate $WORK/myenv/bin/activate
If you already are on the scratch filesystem, the following shorter command can also be used. Note -n
doesn’t allow using “/” so you end up creating conda environment in the current directory.
conda create -n myenv python=3.12
Conda environments can also be activated using:
conda activate $WORK/myenv
Once this is done, you are able to use Python normally, as you would on a personal computer with commands such as
conda install -y numpy scipy matplotlib
pip install pillow
Do not use the conda install
command after you have installed a package using pip
! This will create inconsistencies in the environment.
Better install all packages using conda
and only run pip
as the last command.
Loading the environment in a batch script
You repeat the steps for loading the environment manually in your batch script.
This includes the source command and the path.
Be careful with the path and the partition selection because the variable $WORK
points to different locations (as detailed in Storage System and specifically Scratch/Work page).
module load miniforge3
source activate $WORK/myenv/bin/activate
# OR
# conda activate $WORK/myenv
Updating environments
We do not recommend updating environments. It is safer to recreate them from scratch as soon as you have to use new or different packages.
Many packages offer a file with the list of required packages and versions, which you can use to set up a new environment. The same goes for packages you always need. Simply create a requirements file and use it to set up fresh environments every time you need to change something. Remember to delete the old environment.