简体   繁体   English

IPython Notebook ipywidgets 不显示

[英]IPython Notebook ipywidgets does not show

I created a table with an interactive slider that allows me to toggle between different periods on my table.我创建了一个带有交互式滑块的表格,允许我在表格的不同时间段之间切换。 It was working for the past few days, until today, when I re-ran the notebook, the slide bar doesn't show anymore.过去几天它一直在工作,直到今天,当我重新运行笔记本时,滑块不再显示。 No error messages appear.不会出现错误消息。 The code seem to run just fine, as the table appears, but the slide bar just doesn't appear.当表格出现时,代码似乎运行得很好,但只是没有出现滑动条。 I didn't change my code either, as I was working on a separate part of my notebook.我也没有更改代码,因为我正在处理笔记本的一个单独部分。

I tried many approaches, including searching in this space but was still unable to come up with a solution.我尝试了很多方法,包括在这个空间中搜索,但仍然无法提出解决方案。 I was wondering if anyone faced a similar issue, and have any solution to this.我想知道是否有人遇到过类似的问题,并且对此有任何解决方案。

Below is my code snippet.下面是我的代码片段。 Anything before was solely to get my data into the desired form for tabulation.之前的任何事情都只是为了将我的数据转换为所需的表格形式。

from IPython.display import display
from ipywidgets import widgets, interactive
v = interactive(by_q, quarter=(['q1y2015', 'q2y2015', 'q3y2015', 'q4y2015']), days=(1, 180))
display(v)

With the new version of ipywidgets , I ran into this problem, but then I found on their github readme that you now need to follow使用新版本的ipywidgets ,我遇到了这个问题,但后来我在他们的 github 自述文件中发现你现在需要遵循

pip install ipywidgets

with

jupyter nbextension enable --py widgetsnbextension

That cleared the problem up for me.这为我解决了问题。

在没有希望的情况下搜索了一段时间后,我意识到我需要

jupyter labextension install @jupyter-widgets/jupyterlab-manager

If you've already got [an older version] of ipywidgets installed in Jupyter and you're seeing this problem (you'll probably be seeing javascript errors in the browser console) then you need to run the install command to update the relevant files eg:如果您已经在ipywidgets安装了 [旧版本] 的ipywidgets并且您看到了这个问题(您可能会在浏览器控制台中看到 javascript 错误),那么您需要运行install命令来更新相关文件例如:

jupyter nbextension install --user --py widgetsnbextension

And you may also need to rerun the enable command eg:您可能还需要重新运行enable命令,例如:

jupyter nbextension enable --user --py widgetsnbextension

Note: the --user argument may need to be different if you're using a virtualenv or other environment - see the ipywidget docs for more details.注意:如果您使用的是 virtualenv 或其他环境,则--user参数可能需要不同 - 有关更多详细信息,请参阅ipywidget 文档

Might have been a stupid mistake of mine, but in case you are using virtual environments, just keep properly in mind what is running from where.可能是我犯的一个愚蠢的错误,但是如果您使用的是虚拟环境,请正确记住从何处运行的内容。

You might properly run Jupyter from inside your current environment every time as needed, or might have a root env from which you always start the Jupyter you will end up using for all your environments.您可能每次都根据需要从当前环境中正确运行 Jupyter,或者可能有一个根环境,您总是从中启动 Jupyter,最终将用于所有环境。

For the latter case, what you need to be sure is to enable nbextension for the Jupyter you are actually running, instead of mistakenly run the command from within your currently active environment.对于后一种情况,您需要确保为实际运行的 Jupyter 启用 nbextension,而不是在当前活动的环境中错误地运行命令。

I think plot.ly imports a function called display which overrides the function display from ipython.我认为 plot.ly 导入了一个名为display的函数,它覆盖了 ipython 中的函数display Try changing the order of imports or simply import the function under a different name尝试更改导入顺序或简单地以不同的名称导入函数

Adding to Alexander Svetly's answer, running:添加到 Alexander Svetly 的回答中,运行:

jupyter labextension install @jupyter-widgets/jupyterlab-manager

seemed to get stuck, by adding --debug I was able to see where:似乎卡住了,通过添加 --debug 我能够看到:

jupyter labextension install --debug @jupyter-widgets/jupyterlab-manager
[...]
npm notice 📦  @jupyter-widgets/jupyterlab-manager@3.0.0-alpha.2
[...]
Fetching URL: https://registry.yarnpkg.com/@jupyter-widgets%2Fjupyterlab-manager

Looks like it's trying to install version 3 but I am using version 2.2.9 of Jupyter Lab, so what finally worked was:看起来它正在尝试安装第 3 版,但我使用的是 Jupyter Lab 的 2.2.9 版,所以最终成功的是:

jupyter nbextension enable --py widgetsnbextension --sys-prefix
jupyter labextension install --debug @jupyter-widgets/jupyterlab-manager@2.0

Apparently, if you are trying to use it on the virtual environment and running on vscode , then jupyter notebook itself doesn't work that efficiently but it works on using ipython <notebook_name> , but in that case you won't be able to visualize widgets.显然,如果您尝试在虚拟环境中使用它并在 vscode 上运行,那么 jupyter notebook 本身并不能有效地工作,但它可以使用ipython <notebook_name> ,但在这种情况下,您将无法可视化小部件。 So the best way is to do jupyter notebook <notebook name> , which will open notebook on chrome, and then change the kernel first, ie choose your virtual environment and run on the chrome.所以最好的方法是做jupyter notebook <notebook name> ,它会在chrome上打开notebook,然后先更改内核,即选择你的虚拟环境并在chrome上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM