【问题标题】:tqdm not counting iterations in jupyter notebooktqdm 不计算 jupyter notebook 中的迭代次数
【发布时间】:2021-05-14 22:32:35
【问题描述】:

我正在使用tqdm 来显示迭代进度。但是它在我的 jupyter notebook 环境中无法正常工作。

我可以的

from tqdm import tqdm
a = 0
for i in tqdm(range(10)):
    a += i

print(a)

有输出

但是,循环中的 print 语句存在问题 (see here)。 当我这样做时

from tqdm.notebook import tqdm
a = 0
for i in tqdm(range(10)):
    a += i

print(a)

我明白了

即迭代已执行,但 tqdm 不考虑它们。

知道如何解决这个问题或问题可能是什么吗?

jupyter --version 的输出是

jupyter core     : 4.7.1
jupyter-notebook : 6.2.0
qtconsole        : not installed
ipython          : 7.20.0
ipykernel        : 5.1.0
jupyter client   : 6.1.11
jupyter lab      : not installed
nbconvert        : 5.6.1
ipywidgets       : 7.6.3
nbformat         : 5.1.2
traitlets        : 5.0.5

编辑 这个问题似乎与 MacOS 相关(我运行的是 10.15.7),因为我在 CentOS 上没有观察到它。

除了我尝试过之外,我还更新了我的 conda 环境

jupyter core     : 4.7.1
jupyter-notebook : 6.2.0
qtconsole        : 5.0.2
ipython          : 7.20.0
ipykernel        : 5.5.0
jupyter client   : 6.1.11
jupyter lab      : not installed
nbconvert        : 6.0.7
ipywidgets       : 7.6.3
nbformat         : 5.1.2
traitlets        : 5.0.5

在 python 3.8.8 上。 (我也在 3.7.10 上试过)。 This issue 讨论了类似的问题,问题似乎与 ipywidgets 有关。

【问题讨论】:

标签: python jupyter-notebook tqdm


【解决方案1】:

我在 Jupyter Lab (3.0.9) 中遇到了同样的问题,这对我有用:

jupyter labextension install @jupyter-widgets/jupyterlab-manager \ 
&& jupyter lab

尽管ipywidgets 应该自动安装labextension,但它并未在jupyter labextension list 中列出。当我手动安装它时,进度条会起作用。

对于经典笔记本,ipywidgets docs 提及:

jupyter nbextension enable --py widgetsnbextension

【讨论】:

  • 原来,我的环境由于某种原因搞砸了。即使我安装了widgetsnbextensionipywidgets,它也没有被正确识别。全新安装我的环境后,现在一切正常。
猜你喜欢
  • 1970-01-01
  • 2018-01-05
  • 2020-08-09
  • 1970-01-01
  • 2021-06-27
  • 1970-01-01
  • 2019-04-14
相关资源
最近更新 更多