Set up Conda on UCloud

The Conda package and environment management system is already included in few applications available on UCloud (see, e.g., JupyerLab and PyTorch).

For more general uses of Conda and its powerful package manager it is convenient to create a local installation and save it in a UCloud project.

Conda is included in all versions of Anaconda and Miniconda. For example, to install the latest version of Miniconda, just start any interactive app on UCloud, such as Terminal, and run the following shell commands:

$ curl -s -L -o /tmp/miniconda_installer.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
$ bash /tmp/miniconda_installer.sh -b -f -p /work/miniconda3

The installation directory, in this case miniconda3, must be created in the default working tree, so that it is available in the job output folder for later use.

Conda can be added to the search path with the command:

$ eval "$(/work/miniconda3/bin/conda shell.bash hook)"

or

$ sudo ln -s /work/miniconda3/bin/conda /usr/bin/conda

Both Conda packages and environments are then installed in /work/miniconda3.

To initialize the current shell for use with Conda, run:

$ conda init

Initializing Conda Environment

It is possible to initialize Conda and a specific Conda environment using the Initialization optional parameter when starting a job on UCloud.

To do so, the first steps are to install Miniconda, make it available for later use, and add Conda to the search path (see details above). Next, a Conda environment myenv can be created. These steps can be done in the same job and only need to be done once.

In subsesequent jobs, it is possible to initialize Conda and myenv by submitting a Bash script (.sh) via the Initialization optional parameter. Be sure to add the miniconda3 directory to /work/ using 'Select folders to use'. The Bash script should at least contain the following:

#!/bin/bash
eval "$(/work/miniconda3/bin/conda shell.bash hook)"
conda init
export MY_ENV=myenv
echo "conda activate $MY_ENV" >> ~/.bashrc

The first line is the interpreter directive. The next two lines add Conda to the search path and initializes the current shell for use with Conda (see details above). The fourth line specifies and saves the name of the environment to be initialized, and the last line appends the shell code to activate myenv to the shell configuration file.