anaconda/nb_conda_kernels

Using nb_conda_kernels with jupyterlab extensions (ipympl specifically)

Closed this issue · 4 comments

Hi! I'm trying out using nb_conda_kernels, and I really like the concept.

I have today performed a clean install of Miniconda and created the following two environments with packages:

  • base: nb_conda_kernels, jupyterlab 3 and ipympl
  • py38: ipykernel and other packages that I intend to use

I have also run the "workaround" commands suggested in the readme

ipympl is essentially a better version of %matplotlib notebook, a backend for matplotlib that provides better plotting inline in the notebook / lab. One calls it by %matplotlib widget in the top of the notebook.

The problem is that when I create a notebook using the py38 kernel and call %matplotlib widget, I get ModuleNotFoundError: No module named 'ipympl'. This makes sense, since the %matplotlib widget magic is calling import ipympl under the hood through matplotlib.

Now, I could install ipympl, in py38, but depends amongst others on jupyter notebook, which in turn installs a large number of dependencies.

Should we be trying to reduce the dependencies over at ipympl (and do you think that will work?), or is there something else that I should be trying?

On a second look, I realise that the depenency issue is not (where "->" means "depends on"):

  • ipympl -> notebook
    but instead:
  • ipympl -> ipywidgets -> widgetsnbextension -> notebook

So, assuming that is a "install requires dependencies" issue, then I should be looking at the widgetsnbextension repo.

I think this issue may instead be interpreted as "how to make ipywidgets work without installing the notebook in the second environment".

Late answer

I think this issue may instead be interpreted as "how to make ipywidgets work without installing the notebook in the second environment".

To put it in a nutshell, you need to install the same version of ipympl (or any widget library) in all environments; the one with JupyterLab/Classical notebook and the kernels in which you want to use the widgets.

The user needs to be aware of some technical structure for ipywidgets. A widget is a set of python code (that needs to exist in every kernels) and Javascript code (that needs to be loaded only in the environment where JupyterLab/Classical notebook is executed). But as the Javascript code and the python code needs to have the same version to work (to ensure the Python and Javascript model are identical), you need to install the same version of the package in all kernels that requires the widgets + the one with JupyterLab/Classical notebook.

@fcollonval is correct on this. There are certain packages that must be installed inside the JupyterLab or Jupyter notebook environment itself, as well as the kernel environment. This is unfortunately unavoidable.