tqdm in Jupyter Notebook prints new progress bars repeatedly

后端 未结 8 792
粉色の甜心
粉色の甜心 2020-12-04 06:33

I am using tqdm to print progress in a script I\'m running in a Jupyter notebook. I am printing all messages to the console via tqdm.write(). Howev

8条回答
  •  孤城傲影
    2020-12-04 07:12

    For everyone who is on windows and couldn't solve the duplicating bars issue with any of the solutions mentioned here. I had to install the colorama package as stated in tqdm's known issues which fixed it.

    pip install colorama
    

    Try it with this example:

    from tqdm import tqdm
    from time import sleep
    
    for _ in tqdm(range(5), "All", ncols = 80, position = 0):
        for _ in tqdm(range(100), "Sub", ncols = 80, position = 1, leave = False):
            sleep(0.01)
    

    Which will produce something like:

    All:  60%|████████████████████████                | 3/5 [00:03<00:02,  1.02s/it]
    Sub:  50%|██████████████████▌                  | 50/100 [00:00<00:00, 97.88it/s]
    

提交回复
热议问题