如何解决“Error: Object 'jupyter.widget' not found in registry”?

6

我正在在 Kubernetes 上的 JupyterHub 中运行 JupyterLab。

我尝试使用例如以下方式显示小部件:

from ipywidgets import interact

@interact(x=(0, 100, 10))
def p(x=50):
    pass

实验室笔记本印出的是错误的交互式小部件:

interactive(children=(IntSlider(value=50, description='x', step=10), Output()), _dom_classes=('widget-interact...

在检查 Javascript 控制台时:
default.js:129 Error: Object 'jupyter.widget' not found in registry
    at default.js:1474
    at new Promise (<anonymous>)
    at Object.loadObject (default.js:1453)
    at DefaultKernel.<anonymous> (default.js:919)
    at Generator.next (<anonymous>)
    at default.js:9
    at new Promise (<anonymous>)
    at push.YC29.__awaiter (default.js:5)
    at DefaultKernel._handleCommOpen (default.js:911)
    at DefaultKernel.<anonymous> (default.js:1018)

我尝试了许多不同的组合:

!pip install ipywidgets
!pip install widgetsnbextension --upgrade
!pip install widgetslabextension --upgrade
!conda install -n base -y --override-channels -c main -c conda-forge widgetsnbextension ipywidgets nodejs
!jupyter nbextension enable --py widgetsnbextension
!jupyter labextension enable widgetsnbextension
!jupyter labextension list
!jupyter labextension install @jupyter-widgets/jupyterlab-manager
!jupyter lab clean
!jupyter lab build
!pip install --upgrade Nodejs
!npm install -g npm yarn
!jupyter serverextension enable --py jupyterlab --sys-prefix

jupyterlab当前版本为1.0.0,jupyterlab-manager当前版本为1.0。

一切就绪后,我如何传播更改?

NB 如果我重新启动jupyterlab容器,则所有更改都将丢失。

我愿意做任何事情-打印版本、pip freeze、运行测试、重排/重述这个问题。

有没有人远程知道如何解决这个问题?

请帮忙!

以下内容没有帮助:

如何在Jupyter Lab中使ipywidgets工作?

https://ipywidgets.readthedocs.io/en/latest/user_install.html#installing-the-jupyterlab-extension

显示小部件的问题/ipywidgets安装不成功

https://github.com/jupyter-widgets/ipywidgets/issues/2220

https://github.com/jupyter-widgets/ipywidgets/issues/2514

https://github.com/jupyter-widgets/ipywidgets/issues/2483

https://github.com/twosigma/beakerx/issues/7520

https://github.com/jupyterlab/jupyterlab/issues/6998

https://jupyterhub.readthedocs.io/en/stable/troubleshooting.html

https://github.com/jupyter-widgets/ipywidgets/issues/1949

https://github.com/jupyter-widgets/ipywidgets/pull/1962

3个回答

2

利用https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214,在一个运行于jupyterhub上的jupyterlab终端中执行以下命令:

pythonversion=3.7
labversion=0.34.12
labmanagerversion=0.37.4
ipywidgetsversion=7.4.2

conda install ipywidgets=$ipywidgetsversion -c conda-forge -y --override-channels -c main
conda install jupyterlab=$labversion  -y -c conda-forge --override-channels -c main
jupyter-labextension install @jupyter-widgets/jupyterlab-manager@$labmanagerversion

此时,可能会对执行jupyter lab clean; jupyter lab build感兴趣。

然后,在同一jupyterlab窗口中运行的.ipynb笔记本中,点击重新启动内核按钮。

重要提示:不要忘记还要刷新浏览器页面-否则所有努力都将白费。:\

然后执行示例:

from ipywidgets import interact

@interact(x=(0, 100, 10))
def p(x=50):
    pass

我从未想过会有这一天,但是——瞧!小部件终于出现了!

遗憾的是,设置非常敏感,需要安装其他扩展程序,并且兼容版本的组合非常特定。

enter image description here


希望能够让interact()也正常工作,我尝试使用jupyter/scipy-notebook Docker镜像,但是一切都崩溃了,在浏览器控制台中出现了一个错误,例如:..main.abf319f10d4c4ee43bc1.js”因MIME类型(“text/html”)不匹配而被阻止(X-Content-Type-Options: nosniff) - Marcus Ottosson

0

既然您已经尝试了几种潜在的解决方案却没有成功,也许探索 JupyterLab 和 Kubernetes 在后端如何相互交互的可能性是明智的选择。如果这是问题所在,您可能需要将安装语句添加到底层容器文件中并重新构建它,以便正确的扩展在构建时安装。您是否正在使用 Dockerfile?您是否有编辑正在部署的底层软件容器的必要权限?如果两者都不是,那么是否有系统管理员可以联系?


-1

我不在k8s上,但如果有其他人因为同样的错误而来到这里,我的解决方法是运行:

jupyter labextension install @jupyter-widgets/jupyterlab-manager

重新启动内核,重新加载页面等。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接