'tqdm prints an empty bar after loop ends

tqdm prints an empty bar after loop ends. I tried implementing this solution, but with no success.

The problem does not exist if I remove the print statement (see code).

My code is:

for PhotoIdx in tqdm(range(Nphotos), position=0, leave=True):
    .... 
end
print("something")
return x

I attach a photo with what is outputted to the terminal (the third bar is from another python file).

enter image description here



Solution 1:[1]

This appears to be a Pycharm issue, which can be fixed by editing the Run/Debug Configuration in Pycharm and checking the box that says "Emulate terminal in output console"

enter image description here

The standard output terminal appears to have trouble with properly outputting text applications that use certain terminal features, although I don't know the exact cause of this particular problem.

Solution 2:[2]

it seems to be a bug from Pycharm. It's working fine inside the terminal. Have a good day

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Seguine
Solution 2 Stef500