Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tqdm progressbar and colorama do not work together

I want to use colorama, but I already use tqdm in my code.

Example:

import colorama as color
import tqdm as tqdm  # without line it's working
print(color.Fore.GREEN + 'Green text')

It's working fine without tqdm, but if I import tqdm, colorama does not color the text until I restart the console. I use IPython console with Spyder (Python 3.6).

Is there a way I can use these packages together?

like image 329
Balázs Nagyillés Avatar asked Mar 29 '17 15:03

Balázs Nagyillés


2 Answers

try it as follow (https://github.com/tqdm/tqdm/issues/450)

from tqdm import trange
from colorama import Fore
for i in trange(int(7e7),
    bar_format="{l_bar}%s{bar}%s{r_bar}" % (Fore.GREEN, Fore.RESET)):
    pass
like image 161
Nàéèm Avatar answered Sep 22 '22 19:09

Nàéèm


import colorama as color
import tqdm as tqdm 
import os

os.system('cls')
print(color.Fore.GREEN + 'Green text')

tqdm doesn't works if there is any other activity going on or was previously run on your terminal.

so its better to once clear your terminal screen at the starting of your code using os.system('cls') . This works fine for me.

like image 24
Akshansh Saxena Avatar answered Sep 21 '22 19:09

Akshansh Saxena