A picture of me.

Tom Hodson

Maker, Baker Programmer Reformed Physicist RSE@ECMWF


Jupyter and Conda setup

These are my notes to myself about how to setup jupyter+conda/mamba environments.

Use micromamba instead of conda

Mamba is hugely faster than conda. Use minimamba installed with brew.

Put this in the ~/.condarc (which mamba obeys too):

1channel_priority: strict
2channels:
3  - conda-forge

Useful commands I always forget

Note I’ve added -y to these commands to skip the confirmation dialog. Create env on command line: mamba create -c conda-forge -n envname python=3.11 other_package ... Create env from file: mamba env create -y -f file.yaml Remove env by name: mamba env remove -y -n envname Export only manually installed packages to file: mamba env export --from-history

Jupyter environmnet

Create a jupyter_env.yaml file (so that you can tear it down and rebuild it when everything explodes). Install that.

1name: jupyter
2channels:
3  - conda-forge
4dependencies:
5  - python=3.11 
6  - jupyterlab
7  - nb_conda_kernels # This makes conda envs visible to jupyterlab
8  - jupyterlab_widgets # Makes ipywidgets work in jupyterlab

Notes: (making mamba kernels visible)[https://github.com/Anaconda-Platform/nb_conda_kernels] (making ipywidgets work)[https://ipywidgets.readthedocs.io/en/latest/user_install.html#installing-the-jupyterlab-extension] Can get a env yaml with conda env export --from-history

Child environments

To make other environments visible to the jupyter lab instance and make ipqidgets work (i.e for tqdm progress bars) you need two extra packags:

1name: child
2channels:
3  - conda-forge
4dependencies:
5  - python=3.11
6  - ipywidgets # The child to jupyterlab_widgets
7  - ipykernel # The child to nb_conda_kernels