Managing Jupyter Environments

This Notebook shows how to customize your Jupyter environment to install packages, reset the environment to defaults, and exporting the environment for reproducibility. We also provide some information on general guidelines on using the PAVICS-Hydro JupyterLab instance.

Installing packages

It is possible to install packages to the environment if they are not currently installed. To do so, we should prioritize “mamba” which can be seen as a faster/more efficient conda, and use pip if mamba fails. We can install packages by issuing the command in a notebook cell. Here we will try importing the “seaborn” package, which is not installed by default on PAVICS.

# Attempt to install seaborn. This will fail when run for the first time!

# UNCOMMENT THE FOLLOWING LINE TO TEST THE EXISTENCE OF THE SEABORN PACKAGE. It is currently commented to ensure the automatic notebook checks do not fail for an obvious reason.
# import seaborn

This has failed because the package is not currently installed. Let’s install it using mamba. The same command can be used with pip, simply replace “mamba” with “pip”.

# Install using mamba, and provide the "--yes" option to pre-confirm installation
!mamba install seaborn --yes

# This will take a few seconds to download, install and confirm installation.

We can now import the newly installed package:

# This will now work.
import seaborn

Resetting the environment

If a package is installed that causes conflicts or causes code to break, it is possible to reset the environment by closing the server and respawning a new one, that will have the default packages installed. To do so, simply go to: –> File –> Hub Control Panel –> Stop my server.

Doing so will kill the server, but it will nonetheless keep all of your files. Respawning the server will open a fresh default environment. You can test this now! When you try and re-run the notebook, the first cell will fail again because ‘seaborn’ will have not been installed yet on this server instance.

Exporting your environment

To export your environment to replicate it elsewhere (such as a local installation, or to make a backup in case of future updates), you need to export two elements:

  • The data

  • The installed packages

The data can be exported using the explorer on the left. You can select the files you want to download directly, or you can select “Download current folder as an archive”. This will allow you to keep a copy of your data on your personal computer. However, note that data stored on this server is not removed or purged. Users are encouraged to use storage on an as-needed basis and to remove data that is not required to free-up resources for other users. PAVICS developers will contact users that use unreasonable amounts of storage space in order to find an alternative solution. The same reasoning also applies to computing power. Users can run multiple kernels/notebooks in parallel, but users are encouraged to use resources on an as-needed basis, with power users potentially being contacted to find alternative solutions.

The environment can be exported using the following commands:

Export it to text in this Notebook:

conda env export

Other methods to export environments

You can also export the environment to files, using these commands:

Export it to file with explicit packages and channels:

conda list --explicit>ENV.txt

Export it cross-platform:

conda env export --from-history>ENV.yml