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

Widgets not displaying in notebook

Open Wheels2050 opened this issue 3 years ago • 6 comments

Applies To

  • [X] Notebooks (.ipynb files)
  • [ ] Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

When trying to use interactive plots in a notebook via %matplotlib widget, no plot is shown in the output. For example, this code fails:

%matplotlib widget
import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4, 5])

This appears to be an interaction with the widget sources. If I have the following option configured in my settings:

"jupyter.widgetScriptSources": [ "jsdelivr.com", "unpkg.com" ],

then no plots appear and errors arise (shown in the Jupyter Output logs below). However, if I delete that setting, the plots appear and work as expected.

This problem has only appeared in the last one or two weeks, and before that I did not experience any issues.

VS Code Version

1.71.0

Jupyter Extension Version

v2022.8.1002431955

Jupyter logs

info 12:2:41.952: Started kernel default_venv (Python 3.8.10)., (Raw session started and connected)
info 12:2:41.953: Finished connecting 7b30d229-8a05-4f19-8fdb-93aaeabacf05
info 12:2:41.994: UpdateWorkingDirectoryAndPath in Kernel
info 12:2:41.994: Executing silently Code (busy) = import os\nimport sys\n%cd "//home/wheels2050/devel/scratch"\nif os.getcwd() not in sys.path:\nsys.path
info 12:2:42.367: Executing silently Code (completed) = import os\nimport sys\n%cd "//home/wheels2050/devel/scratch"\nif os.getcwd() not in sys.path:\nsys.path with 1 output(s)
info 12:2:42.369: Waiting for idle on (kernel): 28696b6e-6d2c-4ed3-8cab-fd079dbfc5af -> idle
info 12:2:42.369: Finished waiting for idle on (kernel): 28696b6e-6d2c-4ed3-8cab-fd079dbfc5af -> idle
info 12:2:42.384: Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
info 12:2:42.385: Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
info 12:2:42.407: Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
info 12:2:42.407: Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
info 12:2:42.407: Widget Message: data-base-url set to https://file%2B.vscode-resource.vscode-cdn.net/home/wheels2050/.vscode/extensions/ms-toolsai.jupyter-2022.8.1002431955/tmp/scripts/40e9f355505ee45e308aaa67dbba9888d0afda3afe9284e655b8e00c43fceaa5/jupyter
info 12:2:42.407: Widget Message: data-base-url set to https://file%2B.vscode-resource.vscode-cdn.net/home/wheels2050/.vscode/extensions/ms-toolsai.jupyter-2022.8.1002431955/tmp/scripts/40e9f355505ee45e308aaa67dbba9888d0afda3afe9284e655b8e00c43fceaa5/jupyter
info 12:2:45.266: Execute Cell 0 /home/wheels2050/devel/scratch/bar.ipynb
info 12:2:46.903: Widget Message: WidgetManager: Loading class LayoutModel:@jupyter-widgets/base:1.2.0
info 12:2:46.921: Widget Message: WidgetManager: Loading class LayoutModel:@jupyter-widgets/base:1.2.0
info 12:2:46.970: Widget Message: WidgetManager: Loading class MPLCanvasModel:jupyter-matplotlib:^0.11
info 12:2:46.970: Widget Message: Fetch IPyWidget source for jupyter-matplotlib
info 12:2:46.971: [32mFetch Script for {"moduleName":"jupyter-matplotlib","moduleVersion":"^0.11","requestId":"jupyter-matplotlib:^0.11:1662690766926"}
info 12:2:46.971: [32mFetch Script for jupyter-matplotlib
info 12:2:46.972: [32mSearching for Widget Script jupyter-matplotlib#^0.11 using cdns jsdelivr.com unpkg.com
info 12:2:47.337: Cell 0 executed with state Success
info 12:2:47.480: Widget Message: Waiting for model to be available before rendering it 433d37f97dbe4b46bffa927bbdcf4622
info 12:2:48.175: [32mWidget Script jupyter-matplotlib#^0.11 found at URI: https://unpkg.com/jupyter-matplotlib@^0.11/dist/index
info 12:2:48.176: Script source for Widget jupyter-matplotlib@^0.11 was found from source cdn
info 12:2:48.176: [32mScript for jupyter-matplotlib, is https://unpkg.com/jupyter-matplotlib@^0.11/dist/index from cdn
info 12:2:48.181: Widget Message: Received IPyWidget scripts [{"moduleName":"jupyter-matplotlib","scriptUri":"https://unpkg.com/jupyter-matplotlib@^0.11/dist/index","source":"cdn"}]
info 12:2:48.181: Widget Message: Source for IPyWidget jupyter-matplotlib found in cdn @ https://unpkg.com/jupyter-matplotlib@^0.11/dist/index.
info 12:2:48.181: Widget Message: Registering IPyWidget jupyter-matplotlib found in https://unpkg.com/jupyter-matplotlib@^0.11/dist/index.
info 12:2:48.196: [32mFetch Script for jupyter-matplotlib
info 12:2:48.197: Script source for Widget jupyter-matplotlib@^0.11 was found from source cdn
info 12:2:48.197: [32mScript for jupyter-matplotlib, is https://unpkg.com/jupyter-matplotlib@^0.11/dist/index from cdn
info 12:2:48.218: Widget Message: Received IPyWidget scripts [{"moduleName":"jupyter-matplotlib","scriptUri":"https://file%2B.vscode-resource.vscode-cdn.net/home/wheels2050/.vscode/extensions/ms-toolsai.jupyter-2022.8.1002431955/tmp/scripts/40e9f355505ee45e308aaa67dbba9888d0afda3afe9284e655b8e00c43fceaa5/jupyter/nbextensions/jupyter-matplotlib/index","source":"local"}]
info 12:2:48.219: Widget Message: Received IPyWidget scripts [{"moduleName":"jupyter-matplotlib","scriptUri":"https://unpkg.com/jupyter-matplotlib@^0.11/dist/index","source":"cdn"}]
info 12:2:48.829: Widget Message: WidgetManager: failed, Loading class MPLCanvasModel:jupyter-matplotlib:^0.11
info 12:2:48.829: Widget Message: WidgetManager: failed, Loading class MPLCanvasModel:jupyter-matplotlib:^0.11
error 12:2:48.830: Widget load failure {} {
  className: 'MPLCanvasModel',
  moduleName: 'jupyter-matplotlib',
  moduleVersion: '^0.11',
  cdnsUsed: false,
  isOnline: true,
  timedout: false,
  error: '{}'
}
info 12:2:48.834: Widget Message: WidgetManager: Loading class MPLCanvasModel:jupyter-matplotlib:^0.11
info 12:2:48.839: Widget Message: WidgetManager: failed, Loading class MPLCanvasModel:jupyter-matplotlib:^0.11
info 12:2:48.839: Widget Message: WidgetManager: failed, Loading class MPLCanvasModel:jupyter-matplotlib:^0.11
error 12:2:48.839: Widget load failure {} {
  className: 'MPLCanvasModel',
  moduleName: 'jupyter-matplotlib',
  moduleVersion: '^0.11',
  cdnsUsed: false,
  isOnline: true,
  timedout: false,
  error: '{}'
}
info 12:2:48.841: Widget Message: WidgetManager: Loading class LayoutModel:@jupyter-widgets/base:1.2.0
warn 12:2:48.843: StdErr from Kernel Process [IPKernelApp] WARNING | No such comm: 433d37f97dbe4b46bffa927bbdcf4622

info 12:2:48.879: Widget Message: WidgetManager: Loading class LayoutModel:@jupyter-widgets/base:1.2.0
info 12:2:48.880: Widget Message: WidgetManager: Loading class ToolbarModel:jupyter-matplotlib:^0.11
info 12:2:48.915: Widget Message: WidgetManager: failed, Loading class ToolbarModel:jupyter-matplotlib:^0.11
info 12:2:48.915: Widget Message: WidgetManager: failed, Loading class ToolbarModel:jupyter-matplotlib:^0.11
error 12:2:48.915: Widget load failure {} {
  className: 'ToolbarModel',
  moduleName: 'jupyter-matplotlib',
  moduleVersion: '^0.11',
  cdnsUsed: false,
  isOnline: true,
  timedout: false,
  error: '{}'
}
info 12:2:48.915: Widget Message: WidgetManager: Loading class ToolbarModel:jupyter-matplotlib:^0.11
info 12:2:48.915: Widget Message: WidgetManager: failed, Loading class ToolbarModel:jupyter-matplotlib:^0.11
info 12:2:48.915: Widget Message: WidgetManager: failed, Loading class ToolbarModel:jupyter-matplotlib:^0.11
error 12:2:48.916: Widget load failure {} {
  className: 'ToolbarModel',
  moduleName: 'jupyter-matplotlib',
  moduleVersion: '^0.11',
  cdnsUsed: false,
  isOnline: true,
  timedout: false,
  error: '{}'
}
info 12:2:48.917: Widget Message: WidgetManager: Loading class LayoutModel:@jupyter-widgets/base:1.2.0
info 12:2:48.917: Widget Message: WidgetManager: Loading class LayoutModel:@jupyter-widgets/base:1.2.0
info 12:2:48.918: Widget Message: WidgetManager: Loading class ToolbarModel:jupyter-matplotlib:^0.11
warn 12:2:48.957: StdErr from Kernel Process [IPKernelApp] WARNING | No such comm: 147930f96d844b81b3cb4265cbabd338

info 12:2:48.957: Widget Message: WidgetManager: failed, Loading class ToolbarModel:jupyter-matplotlib:^0.11
info 12:2:48.957: Widget Message: WidgetManager: failed, Loading class ToolbarModel:jupyter-matplotlib:^0.11
error 12:2:48.957: Widget load failure {} {
  className: 'ToolbarModel',
  moduleName: 'jupyter-matplotlib',
  moduleVersion: '^0.11',
  cdnsUsed: false,
  isOnline: true,
  timedout: false,
  error: '{}'
}
info 12:2:48.959: Widget Message: WidgetManager: Loading class ToolbarModel:jupyter-matplotlib:^0.11
info 12:2:48.959: Widget Message: WidgetManager: failed, Loading class ToolbarModel:jupyter-matplotlib:^0.11
info 12:2:48.959: Widget Message: WidgetManager: failed, Loading class ToolbarModel:jupyter-matplotlib:^0.11
error 12:2:48.959: Widget load failure {} {
  className: 'ToolbarModel',
  moduleName: 'jupyter-matplotlib',
  moduleVersion: '^0.11',
  cdnsUsed: false,
  isOnline: true,
  timedout: false,
  error: '{}'
}
info 12:2:48.961: Widget Message: Received display data message 433d37f97dbe4b46bffa927bbdcf4622
info 12:2:48.961: Widget Message: Error: Failed to render widget 433d37f97dbe4b46bffa927bbdcf4622, Error: Module jupyter-matplotlib, semver range ^0.11 is not registered as a widget module
info 12:2:48.961: Widget Message: Received display data message 433d37f97dbe4b46bffa927bbdcf4622
warn 12:2:48.971: StdErr from Kernel Process [IPKernelApp] WARNING | No such comm: 7792cf82f53c49e79b821b71367c4717

Coding Language and Runtime Version

Python v3.8.10

Language Extension Version (if applicable)

v2022.14.0

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Local

Wheels2050 avatar Sep 09 '22 02:09 Wheels2050

@Wheels2050 I'm sorry you're running into this issue.

Do you have ipywidgets 8 installed in your environment. Please could you check that, if you do, then please install ipywidgets 7.7.2 to get this working. We currently do not support the latest version of IPyWidgets 8.*

DonJayamanne avatar Sep 09 '22 03:09 DonJayamanne

@DonJayamanne Thank you for the quick response. I currently have ipywidgets 7.7.2 installed (I came across that as a possible solution before).

I did have to downgrade from 8 after I encountered the issue. Is it possible that the issue is related to the downgrade?

Here is the output of pip freeze, for reference:

argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
asttokens==2.0.8
attrs==22.1.0
backcall==0.2.0
beautifulsoup4==4.11.1
bleach==5.0.1
cffi==1.15.1
cycler==0.11.0
debugpy==1.6.3
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
executing==1.0.0
fastjsonschema==2.16.1
fonttools==4.37.1
importlib-metadata==4.12.0
importlib-resources==5.9.0
ipykernel==6.15.2
ipympl==0.9.2
ipython==8.5.0
ipython-genutils==0.2.0
ipywidgets==7.7.2
jedi==0.18.1
Jinja2==3.1.2
jsonschema==4.15.0
jupyter-core==4.11.1
jupyter_client==7.3.5
jupyterlab-pygments==0.2.2
jupyterlab-widgets==1.1.1
kiwisolver==1.4.4
lxml==4.9.1
MarkupSafe==2.1.1
matplotlib==3.5.3
matplotlib-inline==0.1.6
mistune==2.0.4
nbclient==0.6.7
nbconvert==7.0.0
nbformat==5.4.0
nest-asyncio==1.5.5
notebook==6.4.12
numpy==1.23.2
packaging==21.3
pandocfilters==1.5.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.2.0
pkg_resources==0.0.0
pkgutil_resolve_name==1.3.10
prometheus-client==0.14.1
prompt-toolkit==3.0.31
psutil==5.9.2
ptyprocess==0.7.0
pure-eval==0.2.2
pycparser==2.21
Pygments==2.13.0
pyparsing==3.0.9
pyrsistent==0.18.1
python-dateutil==2.8.2
pyzmq==23.2.1
Send2Trash==1.8.0
six==1.16.0
soupsieve==2.3.2.post1
stack-data==0.5.0
terminado==0.15.0
tinycss2==1.1.1
tornado==6.2
traitlets==5.3.0
wcwidth==0.2.5
webencodings==0.5.1
widgetsnbextension==3.6.1
zipp==3.8.1

Wheels2050 avatar Sep 09 '22 03:09 Wheels2050

please could you try creating a new environment, first installing ipywidgets 7.7.2 and then installing the rest of the packages without specifying a version. let me know if that works.

DonJayamanne avatar Sep 10 '22 23:09 DonJayamanne

Unfortunately that does not fix the problem - I am getting the same error messages as before.

Wheels2050 avatar Sep 11 '22 23:09 Wheels2050

FYI, I have:

from tqdm.notebook import tqdm

for ind_train, ind_test in tqdm(
    kf.split(src_df.index), total=kf.get_n_splits(), desc="k-folds"
):

Upgrading all Python modules today broke the TQDM widget. I've downgraded ipywidgets to 7.* and now TQDM is displayed just fine in VSCode.

Please note, that widget worked just fine with ipywidgets 8 in plain Jupyter Notebook.

FlorinAndrei avatar Sep 20 '22 01:09 FlorinAndrei

@FlorinAndrei you're running into this issue https://github.com/microsoft/vscode-jupyter/issues/8552

DonJayamanne avatar Sep 20 '22 05:09 DonJayamanne

Please could you check that, if you do, then please install ipywidgets 7.7.2 to get this working.

I'm experiencing a related issue. Using ipywidgets 8.x HTML and Text widgets don't show up, while they work fine with version 7.7.2.

Step to reproduce:

from ipywidgets import widgets
widgets.HTML('Test')
widgets.Text('Test')

one line per cell, nothing is displayed with 8.x, but works as expected with 7.x.

mapio avatar Oct 05 '22 07:10 mapio

@mapio IPyWidgets 8 is not yet supported, see https://github.com/microsoft/vscode-jupyter/issues/8552

DonJayamanne avatar Oct 09 '22 22:10 DonJayamanne

Closing as a duplicate of https://github.com/microsoft/vscode-jupyter/issues/8552

DonJayamanne avatar Dec 05 '22 23:12 DonJayamanne

is IPyWidgets 8 supported yet?

I have also downgraded but am having no luck getting the following code to produce an output in VSCode:

btb = widgets.IntText(
 value=7,
 description='Text:'
 )
display(btb)

jmerskine1 avatar Apr 05 '23 10:04 jmerskine1

Any luck with this? Also going through a similar issue.

Adamsmith1234 avatar Jun 15 '23 16:06 Adamsmith1234