python - 检测 Jupyter notebook 时 tqdm 失败
问题描述
我tqdm
用来显示我的代码的进度条。有时我在终端中使用代码,有时我在Jupyter Notebook中使用代码。
除非我弄错了(可能是或者我不会写这个问题),tqdm
否则应该使用以下代码自动确定我是在 Jupyter Notebook 中还是在终端中:
from tqdm.autonotebook import tqdm
def extend(index):
# some code here
# X is a pandas DataFrame defined elsewhere
with mp.Pool(N) as pool:
results = list(
tqdm(pool.imap(extend, X.index), total=len(X)))
进度条在终端中很好地显示,如下所示:
100%|█████████████████████████████████████████| 15035/15035 [35:02<00:00, 7.15it/s]
但是当在 Jupyter Notebook 中调用相同的代码时,会改为显示:
HBox(children=(HTML(value=''), FloatProgress(value=0.0, max=15035.0), HTML(value='')))
难道我做错了什么?我需要做什么才能tqdm
在 Jupyter Notebook和终端中很好地显示?
解决方案
如果你在 JupyterLab 中编辑 notebook,你应该安装jupyterlab_widgets
.
推荐阅读
- python-3.x - sympy 简化/因素/收集的问题
- android - 数据绑定的布局可见性默认值不起作用
- java - 正则表达式在字符串的第一个索引处替换除减号“-”之外的所有无效字符
- sqitch - 用 sqitch 恢复特定的变化?
- python - Python:zip()在列表中的元组内返回两个列表,而不是每个元素的元组列表
- spring - Maven在编译时挂起,我的项目使用java 11,如何解决?
- c# - 正确选择 value=null 的表字段
- angular - 未检测到角度指令
- regex - 在熊猫中使用正则表达式删除数字前面的点
- javascript - React 只为点击的元素提供动画