1

I would like to display two progress bars on my notebook using tqdm on vscode.

I wrote the following code but I do not understand why it is not working:

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()

It displays: issu tqdm img

Env

  • VsCode version: 1.74.2
  • In my Pipfile:
[packages]
tqdm = "*"
ipywidgets = "*"

[requires]
python_version = "3.8"

things I tried

I did test this code on a .py file and it works:

# 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())

In the terminal it displays: working example tqdm

I also tried by replacing the import from tqdm.notebook import tqdm by from tqdm import tqdm on the notebook cell. It works for the single progress bar but not for two (the secondary prgoress bar is not displayed): half working tqdm

I also tried to downgrade ipywidgets in my pipFile: ipywidgets = "7.7.1" following VS Code Interactive is not rendering tqdm.notebook properly it did not change anything.

Vince M
  • 890
  • 1
  • 9
  • 21

0 Answers0