Creating virtual environments for JupyterHub

Viewed 418

I am not able to use virtual environments in JupyterHub version 3.0.14. I have no shell access to the server, but I can use the JupyterHub terminal.

step 1

After reading some documentation, I did this:

  • installed ipykernel in the base environment with: pip install --user ipykernel in the JupyterHub terminal.
  • created a new environment with python -m venv test-env
  • created a new environment with python -m venv test-env2
  • run python -m ipykernel install --user --name=test-env
  • run python -m ipykernel install --user --name=test-env2

After the previous sub-steps, I find the new environments in JupyterHub and I can open a new notebook using the menu "new"->"name of the environment".

step 2

In JupyterHub, I select "new" -> "test-env". In the new notebook, I try and import a new module, for example, hiplot, receiving an error because it is not installed.

To install hiplot in the test-env environment, I open a JupyterHub terminal, activate the environment with source [...]/bin/activate, then pip install hiplot, with success. If I run python from the command line and import hiplot I receive no errors.

step 3

I create a new notebook in the test-env as in step 2 ("new"->"test-env" from the menu), but I still cannot use hiplot, that results not installed. If I try and import it, JupyterHub tells me it is not installed.

QUESTION: After steps 2 and 3, I assume that test-env is not referring to the same environment when accessed from the command line or JupyterHub. Am I correct?

step 4

Inside of a notebook running within the test-env in JupyterHub, I run: `

import sys
!{sys.executable} -m pip install hiplot

After the previous command, I can import hiplot in the current notebook.

BUT

step 5

I open a new JupyterHub notebook in the base or test-env2 environments, where I thought hiplot was not be available. But I was wrong: the module hiplot is available in both of them.

It seems that, in step 4, hiplot has been installed in the base environment and is thus available in all the JupyterHub environments.

I tried to repeat the same steps changing step 1: instead of installing ipykernel in the base environment, I installed it in the test-env, with no success.

QUESTIONS: Is it really possible to use environments in JupyterHub? If it is, what am I doing wrong? I kept reading help pages, but I keep finding instructions with the same commands I used...

QUESTION how can I share a set of installed modules between the system python and the Jupyter notebooks?

0 Answers
Related