tqdm / tqdm

:zap: A Fast, Extensible Progress Bar for Python and CLI

Home Page:https://tqdm.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pycharm + windows new line for every update

chanansh opened this issue · comments

I try the demo code:

from tqdm import trange
from time import sleep

for i in trange(10, desc='1st loop'):
    for j in trange(5, desc='2nd loop', leave=False):
        for k in trange(100, desc='3nd loop'):
            sleep(0.01)

and I get a new line per update rather than a carrier-return (see below sample)
What could be the reason?

1st loop:   0%|          | 0/10 [00:00<?, ?it/s]

2nd loop:   0%|          | 0/5 [00:00<?, ?it/s]


3nd loop:   0%|          | 0/100 [00:00<?, ?it/s]


3nd loop:  10%|█         | 10/100 [00:00<00:00, 92.96it/s]


3nd loop:  20%|██        | 20/100 [00:00<00:00, 93.60it/s]


3nd loop:  30%|███       | 30/100 [00:00<00:00, 94.18it/s]


3nd loop:  40%|████      | 40/100 [00:00<00:00, 94.64it/s]


Sorry but PyCharm does not support progress bars (not just tqdm but any progress bar) because its console interpreter does not support line return \n nor cursor up characters. This has been reported several times but we cannot do anything about it... You should try to run your scripts inside your OS console or another terminal to get the progress bars, or use the tqdm_gui submodule (requires matplotlib but a native tk python version is on the way).

Has the issue fixed yet?

In PyCharm under the run/debug configuration enable "Emulate terminal in output console".
https://stackoverflow.com/questions/45012964/stdout-progress-bars-dont-work-in-pycharm

ah if people confirm that works we can add it to the FAQs.

It works. It can be changed via the following Menu path: Run -> Edit configurations -> Emulate terminal in output console (checkbox)

It works. It can be changed via the following Menu path: Run -> Edit configurations -> Emulate terminal in output console (checkbox)

I cant get it to work with TQDM or any other progress bar I try with Python 3.6 and PyCharmCE 2019.2.3 under Catalina. Neither "emulate terminal in output console" nor run in "python console" have any impact on progressbar output.

It works. It can be changed via the following Menu path: Run -> Edit configurations -> Emulate terminal in output console (checkbox)

I cant get it to work with TQDM or any other progress bar I try with Python 3.6 and PyCharmCE 2019.2.3 under Catalina. Neither "emulate terminal in output console" nor run in "python console" have any impact on progressbar output.

Same here, python 3.8, Pycharm 2019.2.3-1 under arch.

For anyone still seeking a solution: try Emulate terminal in output console
under Configurations -> Edit Configuration -> Execution

This did solve some of my issues with the pycharm console
(Ubuntu, PyCharm Pro 2020.1.1 )

There is no "Emulate terminal in output console" for remote (ssh) interpreters (which are only available in the pro version).

It is possible to edit ~/.ssh/rc to explicitly set the number of lines (PyCharm uses "vt100" as the terminal type):

if [ "$TERM" = "vt100" ]; then stty cols 160 >& /dev/null; fi

Emulate terminal in output console does fix the progress bar for me (PyCharm 2020.2), but at the cost of not being able to use the interactive console when debugging. So that's a no go for my use case.

For anyone still struggling like I was, I just had an old print() hidden in my training loop...

@odedbd you can use the -i Python interpreter option to make the terminal session 'interactive' (you're left with a prompt when it's done).

In the run configuration:
image

So at least you can inspect variables after something runs:

image

But it's not great, I still prefer the PyCharm Python Console with auto-complete etc.

My personal fix is to check sys.stdout.isatty() and avoid multiple/complex tqdm use in environments that aren't TTYs (like PyCharm Python Console)

@davidgilbertson thanksf or the suggestion. For now I simply dropped the tqdm progress bar I was using in favor of simpler logger messages.