rasbt / pyprind

PyPrind - Python Progress Indicator Utility
BSD 3-Clause "New" or "Revised" License
547 stars 65 forks source link

the progressbar can't display in pycharm #35

Closed lzhang6 closed 7 years ago

lzhang6 commented 7 years ago

When I use terminal to run the code, the progress bar is ok while using pycharm, the progressbar can't show in result.

rasbt commented 7 years ago

Hm, maybe PyCharm doesn't show the standard error output? By default, pyprind's objects are using stream=2 to output results to stderr (users suggested this so they can pip the "real" output by their program to other files and such.

If you set stream=1 (which is stdout), does it work?

bar = pyprind.ProgBar(n, stream=1)
for i in range(n):
    time.sleep(timesleep) # your computation here
    bar.update()
lzhang6 commented 7 years ago

Hi

after setting stream to 1,It still can't work

Sincerely

Liang

On 09/06/2016 06:58 PM, Sebastian Raschka wrote:

Hm, maybe PyCharm doesn't show the standard error output? By default, pyprind's objects are using |stream=2| to output results to stderr (users suggested this so they can pip the "real" output by their program to other files and such.

If you set |stream=1| (which is stdout), does it work?

bar= pyprind.ProgBar(n,stream=1) for iin range(n): time.sleep(timesleep)# your computation here bar.update()

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rasbt/pyprind/issues/35#issuecomment-245122216, or mute the thread https://github.com/notifications/unsubscribe-auth/AKGDTa_Skhv8IEhR3yHVWQN0TtIoxtqdks5qnfAugaJpZM4J2Xcl.

rasbt commented 7 years ago

Ah, you are right, for some reason, it doesn't work with stream=1 here. However, I just gave it a try setting the stream manually and it works like a charm ;)

import pyprind
import sys
import time

n = 100
bar = pyprind.ProgBar(n), stream=sys.stdout)
for i in range(n):
    time.sleep(0.1)
    bar.update()

screen shot 2016-09-06 at 10 36 09 pm

Let me know if this works for you as well, and I'd be happy to add a note to the README/docs if this solves the problem.

lzhang6 commented 7 years ago

it works for me, thanks a lot. You should add an example using while loop. tqdm doesn't support while loop

rasbt commented 7 years ago

glad to heart that this solution works and adding a while-loop example is a good idea, thanks for the suggestion (just added one). Btw. do you know if tqdm work with PyCharm out of the box? Never tried this package, looks like an interesting alternative though

lzhang6 commented 7 years ago

tqdm can display in pycharm.

but it didn't support while loop. That is why I give up tqdm to find your package. your package is better than tqdm, becasue support percentage and while loop.

rasbt commented 7 years ago

Ah, I just remembered that I added an sys.stdout.isatty() check for setting the stream, which evaluates to False in PyCharm. Just made a little modification and it should work with PyCharm out of the box. If you like, you can upgrade to 2.9.9 via

pip install pyprind --upgrade

dE1l commented 7 years ago

it's not working in pycharm python console only and in ## PyTest for pyprind 2.11.0 and pycharm 2016.3.3 and python 3.5.

i'm doing this https://github.com/rasbt/pyprind/issues/35#issuecomment-245158319 2017-05-04_12-27-30

rasbt commented 7 years ago

Hi, hm that's weird, just tested in on PyCharm with and without sys.stdout as stream and it seems to work fine in both cases. Can you maybe check via print(pyprind.__version__) that this is indeed pyprind 2.11? Another explanation would be that there might have been some weirdness in PyCharm 2016 regarding standard outputs? ( was running this on the latest version, 2017.1.2)

screen shot 2017-05-04 at 11 18 45 am screen shot 2017-05-04 at 11 18 31 am
umniq commented 6 years ago

The behavior depends on PyCharm's option "Show command line afterwards". If it is on, PyCharm invokes IPython console, you will see each update on the separate line. If it is off, the behavior as expected.

rasbt commented 6 years ago

Thanks for the note. So it seems that it's not a bug after all !? :)

umniq commented 6 years ago

It's PyCharm's issue