How to manage multiple python versions and environments?

Hello,

I’m started using jupyter hub, it’s very nice and useful (and on NixOS it is a very), but I’m missing an important feature: the ability to create multiple environment and python versions.

Currently I’m using uv which does the job flawlessly, but each user has their own jupyter notebook/lab instances, no sharing, no auth and so on. So I wonder how uv could be integrated in jupyterhub. Ideally, one would be able to create/manage from the UI multiple environments and create notebook in those environments.

I couldn’t find a FAQ or a comprehensive page on this in the documentation, but maybe it’s common knowledge that I didn’t learn yet. What is the current best practice for this?

Thank you!

1 Like

Hi @akiross,

Thanks for the question.

My understanding is that on JupyterHub, the administrator can pre-configure some images with pre-installed kernels and each kernel can use it’s own environment.

Users can also create their own environments. One option is to create a environment based on a Git repository using BinderHub.

2 Likes

Hello @rgaiacs, thank you for your help!

BinderHub seems interesting, but I’m not using k8s. I’ll look into it.

Indeed, this feels like a big missing feature for JupyterHub. It seems too important to be a missing feature, so I think it’s me missing something :slight_smile:

Thank you!

Actually, I found a solution: it’s possible to register custom kernels from inside running jupyterlab instances, therefore to use custom uv environments it’s possible to do something like this:

  1. create a virtual environment with $ uv venv --python 3.10 my-env
  2. activate it, e.g. $ . my-env/bin/activate
  3. install ipykernel in that environment: (my-env)$ uv pip install ipykernel
  4. register the kernel: (my-env)$ python -m ipykernel install –user --name=my-env
  5. refresh the jupyterlab web page (this will not stop the kernels)
  6. the kernel can now be used, e.g. go to an open notebook → kernel → change kernel

This should work in jupyterlab in general (and it’s not intimately tied to uv), so works on hub as well. It’s not the most elegant solution, but gives users quite some freedom.