VS Code笔记本中使用tqdm显示双进度条失败的问题求助
VS Code笔记本中使用tqdm显示双进度条失败的问题求助
我想在VS Code的笔记本里用tqdm显示两个进度条,但写的代码无法正常工作,想请教大家原因和解决办法。
我的笔记本代码如下:
import asyncio from tqdm.notebook import tqdm print('\n------ simple p bar ------\n') for i in tqdm(range(10), desc='simple example'): await asyncio.sleep(0.5) print('\n------ two p bar ------\n') primary_p_bar = tqdm(total=10, desc='primary') for i in range(10): secondary_p_bar = tqdm(total=5, leave=False, desc='seconday') for j in range(5): await asyncio.sleep(0.5) secondary_p_bar.update(1) secondary_p_bar.close() primary_p_bar.update(1) primary_p_bar.close()
我的环境信息
- VS Code版本:1.74.2
- Pipfile配置:
[packages] tqdm = "*" ipywidgets = "*" [requires] python_version = "3.8"
我尝试过的方法
把代码放到
.py文件中运行是正常的,代码如下:# type: ignore import asyncio from tqdm import tqdm async def main(): print('\n------ simple p bar ------\n') for i in tqdm(range(10), desc='simple example'): await asyncio.sleep(0.5) print('\n------ two p bar ------\n') primary_p_bar = tqdm(total=10, desc='primary') for i in range(10): secondary_p_bar = tqdm(total=5, leave=False, desc='seconday') for j in range(5): await asyncio.sleep(0.5) secondary_p_bar.update(1) secondary_p_bar.close() primary_p_bar.update(1) primary_p_bar.close() asyncio.run(main())在终端里运行这个
.py文件,双进度条显示正常。尝试把笔记本中的导入语句从
from tqdm.notebook import tqdm改成from tqdm import tqdm:单进度条可以正常显示,但双进度条里的次级进度条还是不显示。按照相关提示降级
ipywidgets到7.7.1版本,修改Pipfile为ipywidgets = "7.7.1",但问题依然没有解决。
备注:内容来源于stack exchange,提问作者Vince M
相关产品推荐
相关产品推荐

