Conda

How to manage your own Conda installation

It is quite possible that the functionality, packages or python library versions provided centrally or from QIM/3DIM (see the Python page) are not sufficient for a particular project. In that case managing a separate environment might be the solution.

There are plenty of good online resources on how to do this. Here we provide a small guide and some tips for using Anaconda/Miniconda on the platform.

Installing miniconda

  • Download anaconda or miniconda, e.g. from here, (look for the Linux 64-bit Installer)
  • Start a terminal, and navigate to the location of the installer
  • Change permissions on the installer:
  • chmod u+x Miniconda3-*.sh
  • Launch installer from terminal:
  • . /Miniconda3-*.sh or Miniconda3-*.sh
  • Browse through the user agreement, and choose location of the installation. During install you’ll be prompted a yes/no for default initialization of conda. Choose no!

If yes is chosen, the following code will be added to the user .bashrc script (located in directory $Home), and the Conda environment is automatically initialized upon starting a terminal, which is probably NOT desirable.

# >>> conda initialize >>>
# !! Contents within this block are managed by ‘conda init’ !!
__conda_setup=”$(‘/home//miniconda3/bin/conda’ ‘shell.bash’ ‘hook’ 2> /dev/null)”
if [ $? -eq 0 ]; then
eval “$__conda_setup”
else
if [ -f “/home//miniconda3/etc/profile.d/conda.sh” ]; then
. “/home//miniconda3/etc/profile.d/conda.sh”
else
export PATH=”/home//miniconda3/bin:\$PATH”
fi
fi
unset __conda_setup
# <<< conda initialize <<<

When choosing no, instead create a shell script as follows:

  • Open a text editor
  • Copy the code above, and change path name of /home/miniconda3/* to the correct location
  • Save the file with the .sh extension – e.g. conda_init.sh – in a suitable directory <FOLDER_SH>

To initialize the installation:

  • Launch a terminal on the desired node type
  • Navigate to the folder where the shell script is located:
  • cd <FOLDER_SH>/
  • Launch the activation shell script:
  • . conda_init.sh
  • This will launch the installation in the base environment for the current terminal session

Creating environment

  • Launch terminal on and node, initialize miniconda in the base environment
  • Create new environment
  • conda create -n <ENV_NAME>

Check out online guides for managing Conda environments, adding packages etc.

Store a ‘copy’ for backup/reproducibility

Make a .yml file, such that you can recreate the environment – either somewhere else (e.g. in an other project, or on an ‘external’ desktop – or in case an update breaks something and the you need to recreate the environment.

Creating a .yml file

  • Launch conda in base environment
  • conda env export > env_filename.yml

Re-creating an environment from a .yml file

  • Launch conda in base environment
  • conda env create -f env_filename.yml