vscode-jupyter icon indicating copy to clipboard operation
vscode-jupyter copied to clipboard

Add support for ipywidgets 8

Open DonJayamanne opened this issue 3 years ago β€’ 12 comments

Packages such as tqdm will not work with the latest version of IPyWidgets 8

Work around - Please install ipywidgets==7.7.2

DonJayamanne avatar Dec 15 '21 15:12 DonJayamanne

Is this a difficult issue to resolve? Do we know what causes the widgets to not display at all?

JP-Ellis avatar Mar 08 '22 02:03 JP-Ellis

know what causes the widgets to not display at all?

we need to update the npm packages used and tweak a few places accordingly

DonJayamanne avatar Mar 08 '22 03:03 DonJayamanne

Is there a temporary workaround which might allow this to work while a permanent fix is being worked on?

JP-Ellis avatar Mar 10 '22 05:03 JP-Ellis

temporary workaround which might

unfortunately no. you can use the older version. i don't think 8 had been released yet.

DonJayamanne avatar Mar 10 '22 05:03 DonJayamanne

All good! While version 8 is not yet marked as stable, it has been available on pypi as a pre-release since February 2020, and the first beta (?) appeared in November 2021. There's a few things I'm looking forward to use once it works well within VS Code :smile:

JP-Ellis avatar Mar 10 '22 06:03 JP-Ellis

Just as a friendly FYI: The first release candidate for 8.0.0 was released on 12 March.

JP-Ellis avatar Mar 24 '22 06:03 JP-Ellis

@JP-Ellis please test the latest pre-release version of the extension, it should work as long as you are not using any of the latest IPyWidget 8.0 widgets/features. I.e. older widgets like slider/textboxes, etc and othe 3rd party widgets will now work when installing ipywidgets 8.0.

DonJayamanne avatar Mar 30 '22 20:03 DonJayamanne

Unfortunately it didn't seem to work for me. I tested the HTML and Dropdown widgets from ipywidgets v8.0.0rc0 and against v2022.4.1000912146 of the extension and nothing showed up. Let me know if there's anything specific you would like me to try or output you wish to see.

JP-Ellis avatar Apr 01 '22 01:04 JP-Ellis

Will test, I tried this with the 8b1, not the rc version. Confirmed, it widgets still do not render in IPYWidgets 8 (there must have been some protocol change in the RC version)

DonJayamanne avatar Apr 05 '22 01:04 DonJayamanne

@JP-Ellis I've just tried this again against the latest pre-release and the v8.0.0rc0 and it seems to work for me Here's the version of Jupyter extension installed v2022.4.1000971004, please could you let me know if this works?

DonJayamanne avatar Apr 05 '22 17:04 DonJayamanne

Found that slider widget works and not the textbox. Will need to dig deeper into this.

DonJayamanne avatar Apr 07 '22 19:04 DonJayamanne

Under the pre-release version of Jupyter plugin (v2022.8.1002431052), running code:

import ipywidgets as ipw
ipw.Text(value="test")

nothing presented.

Log of Jupyter plugin:

info 13:53:43.683: Execute Cell 0 /workspace/notebook/test.ipynb
info 13:53:43.758: Cell 0 executed with state Success
info 13:53:43.867: Widget Message: WidgetManager: Loading class LayoutModel:@jupyter-widgets/base:2.0.0
info 13:53:43.868: Widget Message: WidgetManager: Loading class TextStyleModel:@jupyter-widgets/controls:2.0.0
info 13:53:43.868: Widget Message: WidgetManager: failed, Loading class TextStyleModel:@jupyter-widgets/controls:2.0.0
info 13:53:43.868: Widget Message: WidgetManager: failed, Loading class TextStyleModel:@jupyter-widgets/controls:2.0.0
error 13:53:43.868: Widget load failure {} {
  className: 'TextStyleModel',
  moduleName: '@jupyter-widgets/controls',
  moduleVersion: '2.0.0',
  cdnsUsed: false,
  isOnline: true,
  timedout: false,
  error: '{}'
}
info 13:53:43.870: Widget Message: WidgetManager: Loading class TextModel:@jupyter-widgets/controls:2.0.0
info 13:53:43.918: Widget Message: Received display data message 15e77492c9014d8987f2bc2b950e7ed8
info 13:53:43.929: Widget Message: Waiting for model to be available before rendering it 15e77492c9014d8987f2bc2b950e7ed8
info 13:53:43.929: Widget Message: Error: Failed to render widget 15e77492c9014d8987f2bc2b950e7ed8, Error: Module @jupyter-widgets/controls, semver range ^2.0.0 is not registered as a widget module

tongda avatar Sep 06 '22 05:09 tongda

FWIW, ipywidgets version 8+ is now in conda-forge (and has been so for a month or so), so anyone who uses vscode with conda environments that specify conda-forge as a channel will be pulling in 8.0.2 by default these days.

E.g. conda create --yes --name tqdm-trouble-cf -c conda-forge python tqdm jupyter will create an environment in which tqdm won't work anymore on vscode (though some of the older widgets like IntSlider do still work).

Simple repro:

from tqdm.auto import tqdm
for i in tqdm(list(range(10))):
    print(i)
# nada

from ipywidgets import IntSlider
IntSlider()
# works

Anyway, just posting this as there are going to be more folks with weird widget failures now that ipywidgets 8+ is starting to trickle into common package sources...

zpincus avatar Sep 30 '22 19:09 zpincus

I had to pin ipywidgets to the previous generation in my install scripts, or else VSCode would fail. This is annoying.

ipywidgets==7.*

FlorinAndrei avatar Oct 01 '22 02:10 FlorinAndrei

Required work to get this working in VS Code:

  • [ ] Support running kernel startup code prior to synchronizing kernel messages with webview kernel
    • Buffer kernel messages, see work done in lazy creation of controllers (switching controller from remote kernel spec to live kernel spec)
  • [ ] Support lazy loading of IPyWidget script instead of statitcally contributing this in controller
  • [ ] Support querying version of ipywidgets
  • [ ] Create a loader script that will load version 7 or 8 of ipywidgets
    • Careful thought needs to go into designing this (see last point)
  • [ ] Publish IPyWidget npm package as version 7
    • Plan is to eventually create a seprate branch for v7 after publishing to version 7 (consider this new branch as the branch for maintenance of the older version, hopefully no more changes here)
    • The main branch will subsequently be used for version 8 & the new version of npm will be version 8
  • [ ] Pull in the npm package version 7 into Jupyter extension
  • [ ] Review the renderer script, we might need to make some changes there for
    • https://github.com/microsoft/vscode-jupyter/issues/8635
    • For loading existing widget state from notebooks
    • This will probably end up pulling in be the loader script in some form that loads version 7 or version 8 of the widget script

Challenges:

  • When opening an existing notebook we need to determine the version of IPyWidgets to use
    • Check the modules and version, if we have any modules that start with @jupyter-widgets/ and have a version >= 2, then assume its IPyWidgets 8. Else 7
    • If we cannot find such widgets,
      • Send telemetry for this, to see how often users will fail to load widgest
      • Can we Assume IPyWidgets 8
    • We might not be able load any random script without knowing the version of IPyWidgets in kernel. If we load 7 and the user runs a cell and then we find out that 8 is required, we now need to re-initialize everything with version 8.
    • Hence if we have no idea what the version is, we will not load any widget script (for now)
    • TODO: Find out if we can re-factor widget scripts and toggle the script versions, i.e. reload another version.
  • Accessing ipywidgetsKernel?.renderOutput in the renderer script would have to be async, as we'd need to wait for the widgets scripts to load.
    • The loader script could optionally expose this function, which would internally load the necessary script and then make the call into the loaded script.

DonJayamanne avatar Nov 06 '22 21:11 DonJayamanne

any update on this?

alex180500 avatar Dec 08 '22 13:12 alex180500

I just ran into the same. It took me a while to debug and just found out the ipywidgets 8 does not support VS Code. image

giswqs avatar Jan 20 '23 03:01 giswqs

For the folks asking for updates, @kieferrm posted that "Support ipywidget 8 https://github.com/microsoft/vscode-jupyter/issues/8552 @DonJayamanne" is on the planning for February πŸŽ‰

This is great! I keep getting questions from colleagues about why their widgets aren't working in VS Code πŸ˜„

basnijholt avatar Feb 06 '23 18:02 basnijholt

Nice, so that it will work out of the box now? or we need to install update something?

matifali avatar Feb 10 '23 06:02 matifali

Please wait till early next week and it will work in a prerelease version

DonJayamanne avatar Feb 10 '23 06:02 DonJayamanne

@matifali you should be able to test this within an hour Please install the pre-release version of the Jupyter extension and the latest version of the notebook renderer application in vscode insiders

DonJayamanne avatar Feb 10 '23 15:02 DonJayamanne

@DonJayamanne Do you know when we can expect the fix to this being available in a released version of this extension? That would be very much appreciated! Thanks for fixing this :)

pcmoritz avatar Jun 16 '23 05:06 pcmoritz

We generally close issues when it’s been resolved If not resolved and cleared then we add comments to that effect The support for ipywidgets 8 was added a few releases ago

DonJayamanne avatar Jun 16 '23 05:06 DonJayamanne

Got it, thanks a lot! I think I got confused with the old version that was released on https://github.com/microsoft/vscode-jupyter/releases/tag/2022.09.120 -- it seems on the marketplace a newer version is available. Thanks for your help and sorry for the confusion :)

pcmoritz avatar Jun 16 '23 05:06 pcmoritz

It looks like this issue was tricky to fix, kudos for getting it solved!

pcmoritz avatar Jun 16 '23 05:06 pcmoritz