Running jupyterlab / notebook in another environment

Hi! I’m reading the doc and doing some test installs and was wondering if it’s possible to spawn local single-user servers in another environment than the one JupyterHub is using, and exactly how.

I understood some parts of the doc (and the code) as contradictory in that regard, in particular in the Quickstart installation section you have:

conda install jupyterlab notebook # needed if running the notebook servers in the same environment

which suggests you could run them in another environment, however technically with e.g. LocalProcessSpawner the default is to run jupyterhub-singleuser which is shipped by JupyterHub and not JuperterLab or Notebook, and tries to import and use jupyter_server. It’s also stated elsewhere in the docs that one of the purpose of jupyterhub-singleuser is to check if the version of JupyterHub and e.g. JupyterLab matches, and that seems to contradict the claim it is possible to run the notebook servers in a different environment?

Yes, this is possible and pretty standard. You do need the jupyterhub package in both environments (or jupyterhub-singleuser if you are using conda) because that one package implements both sides of JupyterHub - the authentication in the singleuser-server, and the Hub itself.

Here’s an example of separate envs with conda:

First, create an env for the hub (with jupyterhub), and a second env with jupyterhub-singleuser for users:

conda create -p /env/hub jupyterhub
conda create -p /env/user jupyterhub-singleuser

Then, in your tell the Spawner to launch jupyterhub-singleuser from the user env:

c.Spawner.cmd = "/env/user/bin/jupyterhub-singleuser"

Or, you could make sure the environment is fully activated with:

c.Spawner.cmd = ["conda", "run", "-p", "/env/user", "jupyterhub-singleuser"]

Or you could have more advanced logic for selecting, setting up, or even creating the env in a startup script.

Thanks a lot! Are there version requirements for compatibility between the hub and single user servers?

They should have the same major version, at least.