检测 Jupyter Notebook 时 tqdm 失败

tqdm fails when detecting Jupyter notebook

我正在使用 tqdm to display a progress bar for my code. Sometimes I use the code in the terminal and sometimes I use the code in a 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 中编辑笔记本,则应安装 jupyterlab_widgets