解决JupyterLab中tqdm_notebook进度条不显示问题

文章目录

问题描述

tqdm针对jupyter notebook添加了专门的进度条方法tqdm_notebook()方法,调用语句如下:

from tqdm import tqdm,trange,tnrange,tqdm_notebook
from time import sleep

# 普通进度条
for i in trange(60):
	#TODO:
	sleep(.1)

# 专为notebook设计的进度条
for i in tqdm_notebook(range(600)):
	#TODO:
	sleep(.1)

但是tqdm_notebook在notebook没有显示进度条,并且打印了下面语句:

HBox(children=(IntProgress(value=0, max=822), HTML(value=’’)))

这个问题在github的issue:Jupyterlab and tqdm_notebook #394

解决方案

① 安装启动jupyter的控件拓展1

pip install ipywidgets #或 conda install -c conda-forge ipywidgets
jupyter nbextension enable --py widgetsnbextension

② 安装相关库2

conda install -c conda-forge nodejs
conda install yarn

如果没有安装过Node.js,可以去官方下载Node.js
否则会报错:

An error occured.ValueError: Please install Node.js and npm before continuing installation. You may be able to install Node.js from your package manager, from conda, or directly from the Node.js website (https://nodejs.org).
See the log file for details: C:\Users\ADMINI~1\AppData\Local\Temp\jupyterlab-debug-gorqzsue.log

③ 在JupyterLab中安装扩展3

如果是JupyterLab 3.0以上版本:

conda install -n base -c conda-forge jupyterlab_widgets

如果是JupyterLab 1 或 2版本:

jupyter labextension install @jupyter-widgets/jupyterlab-manager

查看你的JupyterLab版本:

jupyter lab --version

④ 查看已经安装成功的扩展:

jupyter labextension list

在这里插入图片描述
⑤ 此时,在jupyter lab中运行tqdm进度条,能够正常显示出来:
在这里插入图片描述


  1. https://www.it1352.com/1846124.html ↩︎

  2. https://blog.csdn.net/weixin_46088071/article/details/107712775 ↩︎

  3. https://ipywidgets.readthedocs.io/en/latest/user_install.html#installing-in-jupyterlab-3-0 ↩︎

おすすめ

転載: blog.csdn.net/Bit_Coders/article/details/118029347