Jupyter-contrib / jupyter_nbextensions_configurator

A jupyter notebook serverextension providing config interfaces for nbextensions.
Other
981 stars 121 forks source link

jupyterhub configuration #48

Open disimone opened 7 years ago

disimone commented 7 years ago

Dear all,

first of all, thanks for providing this code.

I am trying to use the configurator on a jupyterhub. I installed the contrib_extensions as a user, and enabled them. The extensions run smoothly on the notebook served by the hub-spawned server.

The only problem is that I don't see the configurator entry anywhere in the notebook menu. Nor can I access it from hostname:port/base/url/nbextensions.

Is there something special I need to do? Up to now I just followed the instructions:

pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user

One scpecial thing is that I am using virtual environments. The extensions, as well as the configurator, are installed in a virtualenv. The jupyter server knows about it, though. Indeed, as I said the extensions work smoothly. It is just the configurator I am having problems with.

Thanks for your help,

Andrea.

jcb91 commented 7 years ago

One scpecial thing is that I am using virtual environments. The extensions, as well as the configurator, are installed in a virtualenv. The jupyter server knows about it, though. Indeed, as I said the extensions work smoothly. It is just the configurator I am having problems with.

The extensions (for the most part) only rely on javascript, so they're not necessarily a good gauge for whether your virtualenv is set up correctly. To recap, the general model running here is

  1. jupyterhub is running in some python environment somewhere. You may or may not have access to this env, it doesn't really matter if you're only attempting to install the configurator or a single user.
  2. When you log in, jupyterhub somehow spawns a (possibly new) single-user server for your use. How this happens depends on jupyterhub configuraton, but the default is to switch (linux) user, then effectively run jupyter notebook with a specific base url something like 'user/username`. This happens in some python (possibly virtual) environment, which can be different from the hub env in step 1. This is the env into which you need to install the configurator
  3. When you start a notebook from you single-user server, it starts a new kernel, which (assuming a python kernel) may be in the same virtualenv as the server, but also may not be.

So essentially, I think the issue probably depends on how exactly you're arranging your envs - whether you have the same virtualenv active for the single-user server as well as any kernels. How exactly did you go about setting this up? Did you set up the hub, or is that done by someone already?

jcb91 commented 7 years ago

To clarify, my guess is that what may have happened is:

  1. single-user server spawns without virtualenv, unless hub has been specially configured
  2. kernel spawns with virtualenv / terminal spawns, you activate the virtualenv
  3. using kernel/terminal, changes made to virtualenv, but not to whatever env the single-user server started in. This is ok for nbetensions, as you've installed the javascript files into your per-user directories, so they're accessible from any python env. However, the python packages needed for the configurator are only available in the virtualenv into which they were installed

Also note that you'll need to restart the single-user notebook server in order for any newly-installed serverextensions (such as the configurator) to get loaded.

Hope that makes sense?

disimone commented 7 years ago

Hi,

thanks for your clarifications. This makes a lot more sense now. I suspect the problem may lay in the single-user server not living in any virtualenv. I'll look into this and post my solution, assuming I find one :)

Andrea.

jcb91 commented 7 years ago

:+1: glad it makes sense :)

I suspect the problem may lay in the single-user server not living in any virtualenv.

I think that's likely. If you want your single-user server to start in the virtualenv (and you have access to configure & restart the hub), you might want to check the Spawner.cmd and LocalProcessSpawner.shell_cmd configurables (see jupyterhub/spawner.py#L317-L331 and jupyterhub/spawner.py#L867-L877 for details). It's not trivially easy to activate virtualenvs in subprocess though, so it may be easier to just want to install the configurator into the non-virtualenv, which should also work. To do the latter, you should be able to open a terminal from the single-user server (assuming it lives on a UNIX machine like the hub), possibly deactivate the virtualenv (see e.g. this SO answer for how to deactivate), then just install as you did with the venv active. ALternatively, specify the full path to the pip executable you wish to use for the install, to get it into the non-virtualenv...