Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipykernel error with ipywidgets 8.1 and jupyterlite #3819

Closed
jsignell opened this issue Aug 1, 2023 · 8 comments · Fixed by jupyterlite/pyodide-kernel#53
Closed

ipykernel error with ipywidgets 8.1 and jupyterlite #3819

jsignell opened this issue Aug 1, 2023 · 8 comments · Fixed by jupyterlite/pyodide-kernel#53

Comments

@jsignell
Copy link

jsignell commented Aug 1, 2023

Description

ipywidgets 8.1 raises error with ipykernel

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 from ipywidgets import IntSlider

File /lib/python3.11/site-packages/ipywidgets/__init__.py:54
     51         return
     52     register_comm_target()
---> 54 _handle_ipython()

File /lib/python3.11/site-packages/ipywidgets/__init__.py:52, in _handle_ipython()
     50 if ip is None:
     51     return
---> 52 register_comm_target()

File /lib/python3.11/site-packages/ipywidgets/__init__.py:41, in register_comm_target(kernel)
     39 """Register the jupyter.widget comm target"""
     40 from . import comm
---> 41 comm_manager = comm.get_comm_manager()
     42 if comm_manager is None:
     43     return

File /lib/python3.11/site-packages/ipywidgets/comm.py:18, in get_comm_manager()
     17 def get_comm_manager():
---> 18     if requires_ipykernel_shim():
     19         ip = get_ipython()
     21         if ip is not None and getattr(ip, "kernel", None) is not None:

File /lib/python3.11/site-packages/ipywidgets/comm.py:11, in requires_ipykernel_shim()
      8 if "ipykernel" in sys.modules:
      9     import ipykernel
---> 11     version = ipykernel.version_info
     12     return version < (6, 18)
     13 else:

AttributeError: module 'ipykernel' has no attribute 'version_info'

image

Reproduce

  1. Go to https://jupyterlite.github.io/demo/lab/index.html?path=pyodide/interactive-widgets.ipynb
  2. Run cells

I ran into this while running the examples on https://jupyterlite.github.io/demo/lab/index.html

Expected behavior

Examples work as expected with ipywidgets==8.0
Screenshot from 2023-08-01 12-53-12

@rowanc1
Copy link

rowanc1 commented Aug 1, 2023

Running into the same error in jupyter_lite with https://mystmd.org embedding of widgets, which worked with v8.0.

@martinRenou
Copy link
Member

In order to fix this, the pyodide kernel in jupyterlite needs to update its ipykernel mock package here to include a mock of this version_info. See https://github.com/jupyterlite/pyodide-kernel/tree/main/packages/pyodide-kernel/py/ipykernel/ipykernel

Happy to review a PR, I can also do it myself later this week.

@jtpio
Copy link
Member

jtpio commented Aug 2, 2023

update its ipykernel mock package here to include a mock of this version_info

Wouldn't it be possible to remove the mock if ipykernel was removed in #3811?

@martinRenou
Copy link
Member

Thinking about it, removing the mock of ipykernel means breaking support for old version of ipywidgets that were still relying on importing ipykernel stuffs.

If that is fine for you, then I can indeed remove the ipykernel mock and make use of the comm module. Otherwise, updating the mock to include a version_info variable may be the way to go for now.

@jtpio
Copy link
Member

jtpio commented Aug 2, 2023

Otherwise, updating the mock to include a version_info variable may be the way to go for now.

Ah maybe that's indeed the easiest and less disruptive path for now 👍

We could try using the comm package in a 0.1.0 release of jupyterlite-pyodide-kernel (current still on 0.0.x).

@jtpio
Copy link
Member

jtpio commented Aug 3, 2023

Just released jupyterlite-pyodide-kernel==0.0.10: https://github.com/jupyterlite/pyodide-kernel/releases/tag/v0.0.10

And updated the demo repo to use this version:

image

@jsignell
Copy link
Author

jsignell commented Aug 3, 2023

Wow! Thanks so much - that was super speedy!

@rowanc1
Copy link

rowanc1 commented Aug 10, 2023

Thank you! These are working again in myst!
https://rowanc1.github.io/myst-lite/interactive-articles

lorenz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants