tqdm progressbar and colorama do not work together

2019-05-05 19:43发布

问题:

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?

回答1:

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