代码之家  ›  专栏  ›  技术社区  ›  jtlz2

如何克服“注册表中找不到对象'jupyter.widget'”的错误?

  •  0
  • jtlz2  · 技术社区  · 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。

    一旦一切就绪,我该如何传播变化?

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

    我会做任何事情——打印版本、pip冻结、运行测试、重新格式化/改写这个问题。

    有人知道如何解决这个问题吗?

    请帮忙!

    以下几点没有帮助:

    How to get ipywidgets working in Jupyter Lab?

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

    Problem displaying widgets / ipywidgets install unsuccessful

    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

    0 回复  |  直到 6 年前
        1
  •  1
  •   jtlz2    6 年前

    杠杆作用 https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214 ,在jupyterlab终端中-在jupyterhub上运行-执行:

    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 notebook,点击重启内核按钮。

    重要事项: 也别忘了 刷新 浏览器页面——否则一切努力都将白费:\

    然后执行以下示例:

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

    我从没想过我能活着看到这一天,但是——嘿,普雷斯托——小部件终于出现了!

    可悲的是,安装对其他扩展的安装极其敏感,而且兼容版本的组合非常具体。

    enter image description here

        2
  •  0
  •   Matt L.    6 年前

    由于您已经尝试了几种可能的解决方案,但都没有成功,因此探索这个问题与JupyterLab和kubernetes如何在后端相互交互有关的可能性可能是明智的。如果是这个问题,您可能需要将install语句添加到底层容器文件中,并重新生成它,以便在构建时安装正确的扩展名。你在和dockerfile一起工作吗?您是否具有编辑正在部署的基础软件容器所需的权限?如果对其中任何一个都不满意,您是否可以联系系统管理员?

        3
  •  0
  •   volante    6 年前

    我不在k8s上,但如果其他人登陆这里寻找相同的错误,我的解决方案是运行:

    jupyter labextension install @jupyter-widgets/jupyterlab-manager
    

    重启内核、重新加载页面等。