matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.57k stars 227 forks source link

"Error displaying widget: model not found" #442

Closed prajwel closed 2 years ago

prajwel commented 2 years ago

The problem is identical to closed issue #323.

If I run the script,

%matplotlib widget
from matplotlib import pyplot as plt

fig, ax = plt.subplots()

produces "Error displaying widget: model not found".

The following is the environment which produces the error.

 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59) 
[GCC 10.3.0]
ipympl version: 0.8.8
Selected Jupyter core packages...
IPython          : 8.1.1
ipykernel        : 6.9.2
ipywidgets       : 7.7.0
jupyter_client   : 6.1.12
jupyter_core     : 4.9.2
jupyter_server   : 1.15.6
jupyterlab       : 3.3.2
nbclient         : 0.5.13
nbconvert        : 6.4.4
nbformat         : 5.2.0
notebook         : 6.4.10
qtconsole        : 5.2.2
traitlets        : 5.1.1
Known nbextensions:
  config dir: /home/prajwel/.local/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
  config dir: /mnt/160GB_normal/mambaforge/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
  config dir: /usr/local/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
JupyterLab v3.3.2
/home/prajwel/.local/share/jupyter/labextensions
        jupyter-matplotlib v0.10.2 enabled OK
        @jupyter-widgets/jupyterlab-manager v3.0.1 enabled OK (python, jupyterlab_widgets)

I tried going back versions to fix the problem and found that ipympl==0.8.0 works for me.

The environment where the error goes away is given below.

 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59) 
[GCC 10.3.0]
ipympl version: 0.8.0
Selected Jupyter core packages...
IPython          : 8.1.1
ipykernel        : 6.9.2
ipywidgets       : 7.7.0
jupyter_client   : 6.1.12
jupyter_core     : 4.9.2
jupyter_server   : 1.15.6
jupyterlab       : 3.3.2
nbclient         : 0.5.13
nbconvert        : 6.4.4
nbformat         : 5.2.0
notebook         : 6.4.10
qtconsole        : 5.2.2
traitlets        : 5.1.1
Known nbextensions:
  config dir: /home/prajwel/.local/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
  config dir: /mnt/160GB_normal/mambaforge/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
  config dir: /usr/local/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
JupyterLab v3.3.2
/home/prajwel/.local/share/jupyter/labextensions
        jupyter-matplotlib v0.10.2 enabled OK
        @jupyter-widgets/jupyterlab-manager v3.0.1 enabled OK (python, jupyterlab_widgets)
martinRenou commented 2 years ago

You seem to have a mix of packages installed with mamba and packages installed on your base installation (under /home/prajwel/.local). I can only suggest using conda/mamba for building Python environments and leaving your base installation clean from any packages.

Now concerning the real issue, you seem to have the labextension

/home/prajwel/.local/share/jupyter/labextensions
        jupyter-matplotlib v0.10.2 enabled OK`

Installed, which is only compatible with ipympl version: 0.8.0. So I suggest making sure your Lab extension matches the latest ipympl Python package (just make sure to have the latest Lab extension).

This is something that we discussed with @ianhi, we can improve and ease this constraint but that will require some work on our side.

prajwel commented 2 years ago

Thank you @martinRenou for your help!

I deleted

/home/prajwel/.local/etc/jupyter
/usr/local/etc/jupyter
/home/prajwel/.local/share/jupyter

and it works now. My environment now looks like this.

 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59) 
[GCC 10.3.0]
ipympl version: 0.8.8
Selected Jupyter core packages...
IPython          : 8.2.0
ipykernel        : 6.9.2
ipywidgets       : 7.7.0
jupyter_client   : 6.1.12
jupyter_core     : 4.9.2
jupyter_server   : 1.15.6
jupyterlab       : 3.3.2
nbclient         : 0.5.13
nbconvert        : 6.4.4
nbformat         : 5.2.0
notebook         : 6.4.10
qtconsole        : 5.2.2
traitlets        : 5.1.1
Known nbextensions:
  config dir: /mnt/160GB_normal/mambaforge/etc/jupyter/nbconfig
    notebook section
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
JupyterLab v3.3.2
/mnt/160GB_normal/mambaforge/share/jupyter/labextensions
        jupyter-matplotlib v0.10.5 enabled OK
        @jupyter-widgets/jupyterlab-manager v3.1.0 enabled OK (python, jupyterlab_widgets)

I made a switch to mamba around 1 year back and removed all the previously installed packages maintained by OS version of pip. But I did not remove/notice these directories then.

Thank you for maintaining Ipympl. It is an amazing widget!

martinRenou commented 2 years ago

Happy that you could fix it!