matplotlib / ipympl

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

Error displaying widget: model not found #456

Open recmo opened 2 years ago

recmo commented 2 years ago

Describe the issue

%matplotlib widget
import matplotlib.pyplot as plt

plt.plot([0,1],[0,1])

results in

Error displaying widget: model not found

The javascript console shows:

Could not instantiate widget
Error: Could not create a model.
Uncaught (in promise) Error: Module jupyter-matplotlib, semver range ^0.10.5 is not registered as a widget module

Versions

 3.9.12 (main, Mar 26 2022, 15:44:31) 
[Clang 13.1.6 (clang-1316.0.21.2)]
ipympl version: 0.8.8
Selected Jupyter core packages...
IPython          : 8.2.0
ipykernel        : 6.12.1
ipywidgets       : 7.7.0
jupyter_client   : 7.2.1
jupyter_core     : 4.9.2
jupyter_server   : 1.16.0
jupyterlab       : 3.3.2
nbclient         : 0.5.13
nbconvert        : 6.4.5
nbformat         : 5.3.0
notebook         : 6.4.10
qtconsole        : not installed
traitlets        : 5.1.1
Known nbextensions:
  config dir: /Users/remco/.jupyter/nbconfig
    notebook section
      toggle_all_line_numbers/main  enabled 
      - Validating: OK
      equation-numbering/main  enabled 
      - Validating: OK
      toc2/main  enabled 
      - Validating: OK
      collapsible_headings/main disabled
      nbextensions_configurator/config_menu/main  enabled 
      - Validating: problems found:
        - require?  X nbextensions_configurator/config_menu/main
      scroll_down/main  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
      contrib_nbextensions_help_item/main  enabled 
      - Validating: OK
    tree section
      nbextensions_configurator/tree_tab/main  enabled 
      - Validating: problems found:
        - require?  X nbextensions_configurator/tree_tab/main
  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
/usr/local/share/jupyter/labextensions
        jupyter-matplotlib v0.10.1 enabled OK
        @jupyter-widgets/jupyterlab-manager v3.0.1 enabled OK (python, jupyterlab_widgets)

Other labextensions (built into JupyterLab)
   app dir: /opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/share/jupyter/lab

The following source extensions are overshadowed by older prebuilt extensions:
    jupyter-matplotlib
recmo commented 2 years ago

I've tried removing ipympl and jupyter-matplotlib, but I can not remove the latter:

❯ jupyter labextension uninstall jupyter-matplotlib       
JupyterLab cannot uninstall jupyter-matplotlib since it was installed outside of JupyterLab. Use the same method used to install this extension to uninstall this extension.
❯ pip uninstall jupyter-matplotlib                        
WARNING: Skipping jupyter-matplotlib as it is not installed.

I have no idea how to remove jupyter-matplotlib.

recmo commented 2 years ago

Ok, this worked:

❯ rm -r /usr/local/share/jupyter/labextensions/jupyter-matplotlib
❯ jupyter labextension uninstall jupyter-matplotlib       
Uninstalling jupyter-matplotlib from /opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/share/jupyter/lab/extensions
Building jupyterlab assets (production, minimized)
❯ jupyter labextension uninstall jupyter-matplotlib
No labextension named "jupyter-matplotlib" installed
❯ jupyter labextension list
JupyterLab v3.3.2
/usr/local/share/jupyter/labextensions
        @jupyter-widgets/jupyterlab-manager v3.0.1 enabled OK (python, jupyterlab_widgets)

But I'm still getting the same error.

recmo commented 2 years ago

After running

❯ jupyter labextension install jupyter-matplotlib
Building jupyterlab assets (production, minimized)

It now works, but this feels wrong since the Readme says just running pip ipympl should be enough.

recmo commented 2 years ago

Now the extension manager shows a 500 error and jupyter lab logs the following on the console:

[W 2022-04-10 13:01:26.315 LabApp] Unhandled error
[E 2022-04-10 13:01:26.315 LabApp] {
      "Host": "localhost:8888",
      "Accept": "*/*",
      "Referer": "http://localhost:8888/lab",
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0"
    }
[E 2022-04-10 13:01:26.315 LabApp] 500 GET /lab/api/extensions?1649588486296 (127.0.0.1) 15.13ms referer=http://localhost:8888/lab
[E 2022-04-10 13:01:28.917 ServerApp] Uncaught exception GET /lab/api/extensions?1649588488897 (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/lab/api/extensions?1649588488897', version='HTTP/1.1', remote_ip='127.0.0.1')
    Traceback (most recent call last):
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/web.py", line 1704, in _execute
        result = await result
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 252, in get
        extensions = yield self.manager.list_extensions()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 119, in list_extensions
        pkg_info = yield self._get_pkg_info(name, data)
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 190, in _get_pkg_info
        outdated = yield self._get_outdated()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/web.py", line 1704, in _execute
        result = await result
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 252, in get
        extensions = yield self.manager.list_extensions()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 119, in list_extensions
        pkg_info = yield self._get_pkg_info(name, data)
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 190, in _get_pkg_info
        outdated = yield self._get_outdated()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/web.py", line 1704, in _execute
        result = await result
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 252, in get
        extensions = yield self.manager.list_extensions()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 119, in list_extensions
        pkg_info = yield self._get_pkg_info(name, data)
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 190, in _get_pkg_info
        outdated = yield self._get_outdated()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 769, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/handlers/extension_manager_handler.py", line 221, in _load_outdated
        data = yield self.executor.submit(
      File "/opt/homebrew/lib/python3.9/site-packages/tornado/gen.py", line 762, in run
        value = future.result()
      File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 439, in result
        return self.__get_result()
      File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result
        raise self._exception
      File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 58, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/commands.py", line 565, in get_latest_compatible_package_versions
        return handler.latest_compatible_package_versions(names)
      File "/opt/homebrew/lib/python3.9/site-packages/jupyterlab/commands.py", line 1871, in latest_compatible_package_versions
        raise ValueError(msg % keys)
    ValueError: "['jupyter-matplotlib@0.10.5']" is not a valid npm package
[W 2022-04-10 13:01:28.918 LabApp] Unhandled error
[E 2022-04-10 13:01:28.919 LabApp] {
      "Host": "localhost:8888",
      "Accept": "*/*",
      "Referer": "http://localhost:8888/lab",
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0"
    }
[E 2022-04-10 13:01:28.919 LabApp] 500 GET /lab/api/extensions?1649588488897 (127.0.0.1) 16.96ms referer=http://localhost:8888/lab
rcpeene commented 1 year ago

I am using ipympl within an environment on binder and am getting this problem. In issue #473 some workarounds are discussed, but these are not viable for me, as I don't have direct control over the jupyterlab configuration in binder. Is there a fix for this within ipyml?

The jupyterlab version its running is 3.4.8

martinRenou commented 1 year ago

@rcpeene would you be able to share the environment.yml file you are using for generating your binder? Also please share your postBuild file if you are using one.

rcpeene commented 1 year ago

Here is my requirements.txt

aiohttp==3.8.3
aiosignal==1.3.1
anyio==3.6.2
appdirs==1.4.4
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asciitree==0.3.3
asttokens==2.2.0
async-timeout==4.0.2
attrs==22.1.0
backcall==0.2.0
beautifulsoup4==4.11.1
bidsschematools==0.6.0
bleach==5.0.1
bqplot==0.12.36
ccfwidget==0.5.3
certifi==2022.9.24
cffi==1.15.1
charset-normalizer==2.1.1
ci-info==0.3.0
click==8.1.3
click-didyoumean==0.3.0
cloudpickle==2.2.0
colorama==0.4.6
colorcet==3.0.1
contourpy==1.0.6
cycler==0.11.0
dandi==0.46.6
dandischema==0.7.1
dask==2022.11.1
debugpy==1.6.4
decorator==5.1.1
defusedxml==0.7.1
dnspython==2.2.1
email-validator==1.3.0
entrypoints==0.4
etelemetry==0.3.0
executing==1.2.0
fasteners==0.18
fastjsonschema==2.16.2
fonttools==4.38.0
fqdn==1.5.1
frozenlist==1.3.3
fscacher==0.2.0
fsspec==2022.11.0
gast==0.4.0
h5py==3.7.0
hdmf==3.4.7
humanize==4.4.0
idna==3.4
imageio==2.22.4
importlib-metadata==4.13.0
importlib-resources==5.10.0
interleave==0.2.1
ipydatagrid==1.1.14
ipydatawidgets==4.3.2
ipykernel==6.17.1
ipympl==0.9.2
ipython==8.7.0
ipython-genutils==0.2.0
ipytree==0.2.2
ipyvolume==0.6.0a10
ipyvue==1.8.0
ipyvuetify==1.8.4
ipywebrtc==0.6.0
ipywidgets==7.7.2
isoduration==20.11.0
itk-core==5.3.0
itk-filtering==5.3.0
itk-meshtopolydata==0.10.0
itk-numerics==5.3.0
itkwidgets==0.32.4
jaraco.classes==3.2.3
jedi==0.18.2
Jinja2==3.1.2
joblib==1.2.0
jsonpointer==2.3
jsonschema==4.17.3
jupyter==1.0.0
jupyter_client==7.4.7
jupyter-console==6.4.4
jupyter_core==5.1.0
jupyter-server==1.23.3
jupyterlab-pygments==0.2.2
jupyterlab-widgets==1.1.1
keyring==23.11.0
keyrings.alt==4.2.0
kiwisolver==1.4.4
locket==1.0.0
MarkupSafe==2.1.1
matplotlib==3.6.2
matplotlib-inline==0.1.6
mistune==2.0.4
more-itertools==9.0.0
mpl-interactions==0.22.0
multidict==6.0.2
natsort==8.2.0
nbclassic==0.4.8
nbclient==0.7.2
nbconvert==7.2.5
nbformat==5.7.0
ndx-grayscalevolume==0.0.2
ndx-icephys-meta==0.1.0
ndx-spectrum==0.2.2
nest-asyncio==1.5.6
networkx==2.8.8
notebook==6.5.2
notebook_shim==0.2.2
numcodecs==0.10.2
numpy==1.22.4
nwbinspector==0.4.20
nwbwidgets==0.10.0
packaging==21.3
pandas==1.5.2
pandocfilters==1.5.0
param==1.12.2
parso==0.8.3
partd==1.3.0
pickleshare==0.7.5
Pillow==9.3.0
pip==22.2.2
pkgutil_resolve_name==1.3.10
platformdirs==2.5.4
plotly==5.11.0
prometheus-client==0.15.0
prompt-toolkit==3.0.33
psutil==5.9.4
pure-eval==0.2.2
py2vega==0.6.1
pycparser==2.21
pycryptodomex==3.16.0
pyct==0.4.8
pydantic==1.10.2
Pygments==2.13.0
pynwb==2.2.0
pyout==0.7.2
pyparsing==3.0.9
pyrsistent==0.19.2
python-dateutil==2.8.2
pythreejs==2.4.1
pytz==2022.6
PyWavelets==1.4.1
PyYAML==6.0
pyzmq==24.0.1
qtconsole==5.4.0
QtPy==2.3.0
requests==2.28.1
rfc3339-validator==0.1.4
rfc3987==1.3.8
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.7
scikit-image==0.19.3
scipy==1.9.3
semantic-version==2.10.0
Send2Trash==1.8.0
setuptools==65.5.0
six==1.16.0
sniffio==1.3.0
soupsieve==2.3.2.post1
stack-data==0.6.2
tenacity==8.1.0
terminado==0.17.0
tifffile==2022.10.10
tinycss2==1.2.1
toolz==0.12.0
tornado==6.2
tqdm==4.64.1
traitlets==5.6.0
traittypes==0.2.1
trimesh==3.16.4
typing_extensions==4.4.0
uri-template==1.2.0
urllib3==1.26.13
wcwidth==0.2.5
webcolors==1.12
webencodings==0.5.1
websocket-client==1.4.2
wheel==0.37.1
widgetsnbextension==3.6.1
wincertstore==0.2
xarray==2022.11.0
yarl==1.8.1
zarr==2.13.3
zipp==3.11.0
zstandard==0.19.0

I've fiddled with the versions of ipywidgets and jupyterlab_widgets, due to some confounding dependencies, it seems infeasible to change them.

rcpeene commented 1 year ago

Any updates here?

martinRenou commented 1 year ago

Can you share the output of jupyter labextension list? Please note that it's always better to open your own issue while filling the issue form that asks these informations, those endless issue threads with multiple issue cases are difficult to handle.

rcpeene commented 1 year ago

Here's the output of jupyter labextension list:

JupyterLab v3.4.8
/srv/conda/envs/notebook/share/jupyter/labextensions
        jupyter-offlinenotebook v0.2.2 enabled OK
        jupyterlab_pygments v0.2.2 enabled OK (python, jupyterlab_pygments)
        jupyter-webrtc v0.6.0 enabled OK
        jupyterlab-datawidgets v7.1.2 enabled OK
        jupyter-threejs v2.4.0 enabled OK (python, pythreejs)
        ipydatagrid v1.1.14 enabled OK
        jupyter-matplotlib v0.11.2 enabled OK
        jupyter-vuetify v1.8.4 enabled OK
        ipyvolume v0.6.0-alpha.10 enabled OK
        jupyterlab-plotly v5.11.0 enabled OK
        bqplot v0.5.37 enabled OK (python, bqplot)
        jupyter-vue v1.8.0 enabled OK
        ipytree v0.2.2 enabled OK
        @jupyter-widgets/jupyterlab-manager v3.1.1 enabled OK (python, jupyterlab_widgets)
        @jupyter-server/resource-usage v0.6.3 enabled OK (python, jupyter-resource-usage)

Other labextensions (built into JupyterLab)
   app dir: /srv/conda/envs/notebook/share/jupyter/lab
martinRenou commented 1 year ago

Do you have an error in the JavaScript console?

Oh I see it. jupyter-webrtc could be the culprit. I would suggest creating a new environment without ipywebrtc which does not support ipywidgets 8. If you really want ipywebrtc, you could downgrade to ipywidgets 7.

rcpeene commented 1 year ago

Hmmm, running pip uninstall ipywebrtc doesn't seem to be the fix.