Conda environments#

The NCAR JupyterHub utilizes an extension known as nb_conda_kernels to allow custom conda/mamba environments to be saved and persist across user sessions. These are stored in /home/jovyan/my-conda-envs because /home/jovyan is mounted on what is known as a persistent volume.

Note

Mamba is faster than Conda typically at creating environments. They both work in the same way and both are available on the NCAR JupyterHub.

Creating a new env#

Most of the time well written code will contain a list of packages it requires to run. These typically will be in either a requirements.txt file (for pip) or an environment.yml file (for conda). The following example will follow a workflow where a GitHub repository that contains an environment.yml is cloned in to JupyterHub.

Let’s say you are working on the geocat-examples repository found here. You’ve followed the procedure to clone the repository in to your JupyterHub and now you want to work directly with the code. Before getting started we want to spin up an environment that contains all the packages required for the codebase. In the geocat-examples repository the package list is called conda_environment.yml. If in the File Browser you are in the directory containing the package list you can open a new Launcher tab and open the Terminal. This will open directly in the directory you were present in when launched. If you are not in the directory containing the package list cd to the appropriate directory or use the path in your mamba env create command like in the following example:

mamba env create -f conda_environment.yml

Note

Mamba is faster than Conda when it comes to creating environments. It is recommended to use Mamba but either will work.

It will take a little while to install all the packages and create the environment. As long as everything finishes correctly you should see a message that the new environment can be activated by running conda activate geocat-examples. Please go ahead and run this to test that the new environment activates properly. To exit the environment run conda deactivate. When you go to select a Kernel in your notebook files now you will see the new environment listed along with the base environments that come preinstalled. Congratulations, this new environment is now saved to your JupyterHub instance and can be used at anytime.