ipympl: Failed to load model class 'MPLCanvasModel' from module 'jupyter-matplotlib'

Describe the issue

This example plot is failing:

%matplotlib ipympl
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(3*x)
ax.plot(x, y)

[Open Browser Console for more detailed log - Double click to close this message]
Failed to load model class 'MPLCanvasModel' from module 'jupyter-matplotlib'
Error: No version of module jupyter-matplotlib is registered
    at WidgetManager.loadClass (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/lib_index_js.c47facf974cffc1de06d.js:942:19)
    at WidgetManager.loadModelClass (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/packages_base-manager_lib_index_js.dcca134bd5d3eec26948.js:819:34)
    at WidgetManager._make_model (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/packages_base-manager_lib_index_js.dcca134bd5d3eec26948.js:651:36)
    at WidgetManager.new_model (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/packages_base-manager_lib_index_js.dcca134bd5d3eec26948.js:495:35)
    at WidgetManager.handle_comm_open (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/packages_base-manager_lib_index_js.dcca134bd5d3eec26948.js:405:21)
    at LabWidgetManager._handleCommOpen (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/lib_index_js.c47facf974cffc1de06d.js:815:24)
    at b._handleCommOpen (http://localhost:8888/static/lab/jlab_core.3ff62e44d3544d23c59e.js?v=3ff62e44d3544d23c59e:2:925131)
    at async b._handleMessage (http://localhost:8888/static/lab/jlab_core.3ff62e44d3544d23c59e.js?v=3ff62e44d3544d23c59e:2:927121)

Versions


 3.8.5 (default, Sep  4 2020, 02:22:02) 
[Clang 10.0.0 ]
ipympl version: 0.8.8
Selected Jupyter core packages...
IPython          : 7.28.0
ipykernel        : 6.4.1
ipywidgets       : 8.0.0rc0
jupyter_client   : 7.0.6
jupyter_core     : 4.8.1
jupyter_server   : 1.11.1
jupyterlab       : 3.1.18
nbclient         : 0.5.4
nbconvert        : 6.2.0
nbformat         : 5.1.3
notebook         : 6.4.4
qtconsole        : not installed
traitlets        : 5.1.0
Known nbextensions:
  config dir: /Users/davidlaxer/.jupyter/nbconfig
    notebook section
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
      bqplot/extension  enabled 
      - Validating: OK
  config dir: /Users/davidlaxer/tensorflow-metal/etc/jupyter/nbconfig
    notebook section
      catboost-widget/extension  enabled 
      - Validating: OK
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyterlab-plotly/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
JupyterLab v3.1.18
/Users/davidlaxer/tensorflow-metal/share/jupyter/labextensions
        @jupyter-widgets/jupyterlab-manager v5.0.0-rc.0 enabled OK

Other labextensions (built into JupyterLab)
   app dir: /Users/davidlaxer/tensorflow-metal/share/jupyter/lab
        jupyter-matplotlib v0.11.0 enabled OK
        jupyterlab-plotly v5.7.0 enabled OK


About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 35 (5 by maintainers)

Most upvoted comments

I am experiencing a very similar issue: In a new environment with ipympl==0.9.2, ipywidgets==8.0.2 initially the matplotlib figure is displayed correctly in Jupyterlab with the minimal example:

%matplotlib ipympl
from matplotlib import pyplot as plt
fig, ax = plt.subplots()

A different extension needed an update though and that triggered a Jupyterlab build. After the build finished without errors the same example only yields the error message in the cell output:

[Open Browser Console for more detailed log - Double click to close this message]
Failed to load model class 'MPLCanvasModel' from module 'jupyter-matplotlib'
Error: No version of module jupyter-matplotlib is registered
    at f.loadClass (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.bcbea9feb6e7c4da7530.js?v=bcbea9feb6e7c4da7530:1:74856)
    at f.loadModelClass (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.3e1e5adfd821b9b96340.js?v=3e1e5adfd821b9b96340:1:10729)
    at f._make_model (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.3e1e5adfd821b9b96340.js?v=3e1e5adfd821b9b96340:1:7517)
    at f.new_model (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.3e1e5adfd821b9b96340.js?v=3e1e5adfd821b9b96340:1:5137)
    at f.handle_comm_open (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.3e1e5adfd821b9b96340.js?v=3e1e5adfd821b9b96340:1:3894)
    at _handleCommOpen (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.bcbea9feb6e7c4da7530.js?v=bcbea9feb6e7c4da7530:1:73393)
    at b._handleCommOpen (http://localhost:8888/static/lab/jlab_core.005d4a04b448c938e176.js?v=005d4a04b448c938e176:2:996724)
    at async b._handleMessage (http://localhost:8888/static/lab/jlab_core.005d4a04b448c938e176.js?v=005d4a04b448c938e176:2:998714)

This seems to indicate that something is still not working in the built process. This reminds me of similar issues in the past where in a new environment everything worked but for unclear reasons after an update it became impossible to recover.

A workaround seems to be the complete cycle of conda uninstall jupyterlab ipympl, conda install -c conda-forge jupyterlab ipympl. Just reinstalling ipympl is not enough.

Why is this issue closed? Clearly people (including myself) are still getting this problem

I had the problem mentioned by the poster but got it to work again.

  • Using Python 3.9.12, Conda 22.11.1 in WSL

Problem Description:

  • widgets would not work correctly (non-interactable figures) in Jupyter Notebook and I got the " MPLCanvasModel" error in Jupyter Lab with no cell output (only error)

Attempts to fix it…

  • I tried to install widgets using the Jupyterlab 3 installation instructions shown here https://ipywidgets.readthedocs.io/en/7.x/user_install.html
  • I used (conda install nodejs -c conda-forge --repodata-fn=repodata.json) to get the latest version of nodejs
  • It didn’t work so I also tried the installation instruction for JYL2 as well with (jupyter labextension install @jupyter-widgets/jupyterlab-manager) in both my base environment and other environments (was a mistake)
  • When I used (jupyter labextension list) in both my base and separate environments I saw
  • (@jupyter-widgets/jupyterlab-manager v3.1.1 enabled OK (python, jupyterlab_widgets)) in other environment
  • and ( @jupyter-widgets/jupyterlab-manager v5.0.5 enabled OK (python, jupyterlab_widgets)) in base environment
  • This made me suspect that there were conflicting versions of jupyterlab-manager for different environments.

The fix…

  • I sought to remove my extensions so I used (jupyter lab clean --all) in both environments
  • Then I uninstalled jupyterlab from my base and other environment using (conda uninstall jupyterlab)
  • Then I reinstalled jupyterlab in my base environment (only) and reinstalled widgets in the environments I wanted to use
  • This seemed to fix the issue and now I can interact with my figures in jupyterlab!
  • I still get 2 errors. One is (Failed to fetch ipywidgets through the “jupyter.widget.control” comm channel, fallback to fetching individual model state. Reason: Control comm was closed too early) and the other is (Module @jupyter-widgets/base, version ^1.2.0 is not registered, however 2.2.0 is)

Thank you so much for sharing! I’ve been trying for a few days now to fix the interactive Jupyter plot environment issue and had absolutely no luck until I saw this solution. I am working on an Azure ML compute instance (VM).

For anyone else still running into the issue, the following helped me in addition to the quoted solution:

  • Run pip uninstall ipympl or conda uninstall ipympl in both environments after jupyter lab clean --all
  • Use conda to install jupyterlab in the base environment (I used conda install -c conda-forge jupyterlab=3.2.4)
  • Use conda to install ipympl in the kernel environment (I used conda install -c conda-forge ipympl=0.8.7)
  • Shut down / restart Jupyter
  • When you open your notebook in JupyterLab, select your kernel (not base), restart the kernel, and hard refresh your browser page (ctrl + shift + R)

Not sure how my jupyter got into this state, but for me what solved this once and for all was:

  1. Stop kernel
  2. jupyter lab build (in same terminal)
  3. Restart kernel
  4. Hard refresh the lab page

Hope this helps someone else!

I’m still experiencing this issue with ipywidgets 8.0.1 and ipympl 0.9.2, which is the latest release and includes gh-461. Should I open a new one, or continue the conversation here?

ipympl-failing

[Open Browser Console for more detailed log - Double click to close this message]
Failed to load model class 'MPLCanvasModel' from module 'jupyter-matplotlib'
loadClass@https://festive-panini-317af3ac.orchestapp.io/jupyter-server-073b702f-bc66-44c1c87bb737-6ba5-4013/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.083e6b37f2f7b2f04b5e.js?v=083e6b37f2f7b2f04b5e:1:74855
loadModelClass@https://festive-panini-317af3ac.orchestapp.io/jupyter-server-073b702f-bc66-44c1c87bb737-6ba5-4013/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.467514c324d2bcc23502.js?v=467514c324d2bcc23502:1:10721
_make_model@https://festive-panini-317af3ac.orchestapp.io/jupyter-server-073b702f-bc66-44c1c87bb737-6ba5-4013/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.467514c324d2bcc23502.js?v=467514c324d2bcc23502:1:7517
new_model@https://festive-panini-317af3ac.orchestapp.io/jupyter-server-073b702f-bc66-44c1c87bb737-6ba5-4013/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.467514c324d2bcc23502.js?v=467514c324d2bcc23502:1:5137
handle_comm_open@https://festive-panini-317af3ac.orchestapp.io/jupyter-server-073b702f-bc66-44c1c87bb737-6ba5-4013/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.467514c324d2bcc23502.js?v=467514c324d2bcc23502:1:3894
134/v/this._handleCommOpen@https://festive-panini-317af3ac.orchestapp.io/jupyter-server-073b702f-bc66-44c1c87bb737-6ba5-4013/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.083e6b37f2f7b2f04b5e.js?v=083e6b37f2f7b2f04b5e:1:73392
_handleCommOpen@https://festive-panini-317af3ac.orchestapp.io/jupyter-server-073b702f-bc66-44c1c87bb737-6ba5-4013/static/lab/jlab_core.a8a3519a137e0ddfc2a4.js?v=a8a3519a137e0ddfc2a4:2:1066903

This uses jupyterlab-widgets==3.0.2 on the JupyterLab environment (we have 2 separate environments because we’re using https://github.com/jupyter-server/enterprise_gateway/).

Hi @dbl001 it looks as though you have the newest labextension but not the latest python version. Can you please update the python version: pip install --upgrade ipympl and try again

Both @Gilthans and @niwilso answers were helpful. I also had to install the latest version of nodejs (mamba install nodejs)

I had the problem mentioned by the poster but got it to work again.

  • Using Python 3.9.12, Conda 22.11.1 in WSL

Problem Description:

  • widgets would not work correctly (non-interactable figures) in Jupyter Notebook and I got the " MPLCanvasModel" error in Jupyter Lab with no cell output (only error)

Attempts to fix it…

  • I tried to install widgets using the Jupyterlab 3 installation instructions shown here https://ipywidgets.readthedocs.io/en/7.x/user_install.html
  • I used (conda install nodejs -c conda-forge --repodata-fn=repodata.json) to get the latest version of nodejs
  • It didn’t work so I also tried the installation instruction for JYL2 as well with (jupyter labextension install @jupyter-widgets/jupyterlab-manager) in both my base environment and other environments (was a mistake)
  • When I used (jupyter labextension list) in both my base and separate environments I saw
  • (@jupyter-widgets/jupyterlab-manager v3.1.1 enabled OK (python, jupyterlab_widgets)) in other environment
  • and ( @jupyter-widgets/jupyterlab-manager v5.0.5 enabled OK (python, jupyterlab_widgets)) in base environment
  • This made me suspect that there were conflicting versions of jupyterlab-manager for different environments.

The fix…

  • I sought to remove my extensions so I used (jupyter lab clean --all) in both environments
  • Then I uninstalled jupyterlab from my base and other environment using (conda uninstall jupyterlab)
  • Then I reinstalled jupyterlab in my base environment (only) and reinstalled widgets in the environments I wanted to use
  • This seemed to fix the issue and now I can interact with my figures in jupyterlab!
  • I still get 2 errors. One is (Failed to fetch ipywidgets through the “jupyter.widget.control” comm channel, fallback to fetching individual model state. Reason: Control comm was closed too early) and the other is (Module @jupyter-widgets/base, version ^1.2.0 is not registered, however 2.2.0 is)

I don’t see any obvious issue here.

Can you make sure to hard refresh your browser page (ctrl + shift + R), just in case, and try again to run the Notebook cell?