Shared conda environments let instructors and TAs install custom packages and register new Jupyter kernels for their courses, without needing GitHub pull requests or waiting for the new software to be deployed. This is useful for quickly adding or updating software needed for teaching or assignments, providing autonomy to instructors in making quick changes to the instructional environment.
Creating additional conda environments also helps avoid dependency problems: you can install software into a secondary environment that might otherwise break the base environment, keeping your course setup stable and isolated.
If you are interested in piloting this feature in your hub, we encourage you to contact the DataHub team for more information and to express your interest.
Technical Details¶
The software is deployed on the shared cloud file server, not within the hub’s singleuser docker image, so changes to secondary conda environments do not require that the docker image be rebuilt and deployed. Students might only need to restart their notebook servers to see newly installed kernels, and package updates would require that students restart running kernels.
Create a Conda Environment¶
Open a terminal from Jupyterlab and run:
conda initIf you see the “No action taken” error, run:
source ~/.bashrcCreate a conda environment from scratch
conda create --prefix /srv/conda/envs/shared python=3.11 -yYou can create a conda environment from the ‘notebook’ conda environment if ‘notebook’ exists. You can check if notebook exists by running conda env list.
conda list --explicit --prefix /srv/conda/envs/notebook > base-env.txt conda create --prefix /srv/conda/envs/shared --file base-env.txtYou can also create a conda environment from the
baseconda environment:conda list --explicit --prefix /srv/conda > base-env.txt conda create --prefix /srv/conda/envs/shared --file base-env.txtActivate the new environment to start working in it.
conda activate /srv/conda/envs/sharedInstall any additional packages you need for the course.
mamba install numpy pandas -yIf
mambais not available, useconda install ...instead.mambais a faster drop-in replacement forconda.Install
ipykernelif not already installed.mamba install ipykernel -yInstall a kernel that uses your new conda environment.
python -m ipykernel install \ --name shared \ --display-name "Python (<bcourse_id or whatever you want>)" \ --prefix /srv/conda/envs/sharedValidate that the kernel was successfully registered.
jupyter kernelspec listThis will display all available Jupyter kernels.
Optionally deactivate the environment once setup is complete. This is only necessary if you want your running terminal to have access to the original environment.
conda deactivate
Remove a Conda Environment¶
To remove the conda environment, run:
conda env remove --prefix /srv/conda/envs/sharedThis frees up disk space on the shared file server.