Jupyter Notebook 中的 tqdm 反复打印新的进度条 [英] tqdm in Jupyter Notebook prints new progress bars repeatedly
问题描述
我正在使用 tqdm
在我在 Jupyter 笔记本中运行的脚本中打印进度.我正在通过 tqdm.write()
将所有消息打印到控制台.然而,这仍然给了我一个像这样的倾斜输出:
I am using tqdm
to print progress in a script I'm running in a Jupyter notebook. I am printing all messages to the console via tqdm.write()
. However, this still gives me a skewed output like so:
也就是说,每次必须打印新行时,下一行都会打印一个新的进度条.当我通过终端运行脚本时不会发生这种情况.我该如何解决这个问题?
That is, each time a new line has to be printed, a new progress bar is printed on the next line. This does not happen when I run the script via terminal. How can I solve this?
推荐答案
尝试使用 tqdm.notebook.tqdm
而不是 tqdm
,如这里.
Try using tqdm.notebook.tqdm
instead of tqdm
, as outlined here.
这可能就像将导入更改为:
This could be as simple as changing your import to:
从 tqdm.notebook 导入 tqdm
祝你好运!
经过测试,似乎 tqdm
在 Jupyter 笔记本中的文本模式"中实际上运行良好.很难说,因为您没有提供最小示例,但看起来您的问题是由每个打印语句引起的迭代.打印语句在每次状态栏更新之间输出一个数字 (~0.89),这会弄乱输出.尝试删除打印语句.
After testing, it seems that tqdm
actually works fine in 'text mode' in Jupyter notebook. It's hard to tell because you haven't provided a minimal example, but it looks like your problem is caused by a print statement in each iteration. The print statement is outputting a number (~0.89) in between each status bar update, which is messing up the output. Try removing the print statement.
这篇关于Jupyter Notebook 中的 tqdm 反复打印新的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!