Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alive_bar not working properly on PyCharm's "Run" menu option #45

Closed
diogomreiras opened this issue Jun 24, 2020 · 11 comments
Closed

alive_bar not working properly on PyCharm's "Run" menu option #45

diogomreiras opened this issue Jun 24, 2020 · 11 comments

Comments

@diogomreiras
Copy link

Tried to run your simplified example (below) and the bar does now work properly.
Working with PyCharm2020.1.2 on a macOS 10.15.5 with Python3.7.3 using an new empty project and installing alive-progress as suggested on PyPi
The bar only shows itself already completed after the 10s, so no progress is shown.

import time

from alive_progress import alive_bar


def main():
    with alive_bar(10, force_tty=True) as bar:
        for i in range(10):
            time.sleep(1)
            bar()
    print("done")


if __name__ == "__main__":
    main()

I also tried running this code from Terminal. The result is that it shows and updates the bar apparently correctly a few times (3 bars going up and down work fine during the 0/10 progress) but as soon as 1/10 progress is reached by the output of the bar, it prints a bar in a new line for every update...

Am I doing something wrong? 😇 Let me know if you need more info.
Hopefully we can get this beautiful took working for me 2
💪

PS: the gifs on PyPi for the Styles section are not being shown, with a message of size being too big ; )

@diogomreiras
Copy link
Author

According to this there could be a end_line problem.
They seem to suggest that the end of line should be "" and not "\r".
I used the above example printProgressBar() using the suggested change and it works fine on PyCharm and Terminal.

If there would be a manual way to change the line ending for the alive-bar, then I could test if myself, but I found none.

another reference

@diogomreiras diogomreiras changed the title Bar not working properly on PyCharm and Terminal on Mac alive_bar not working properly on PyCharm and Terminal on Mac Jun 24, 2020
@rsalmei
Copy link
Owner

rsalmei commented Jun 24, 2020

Hello @diogomreiras,

I can't reproduce your problem, it does work properly on Pycharm:
on_pycharm

I didn't do anything more than configuring a Python Interpreter with alive-progress 1.5.1 installed, and pasted your exact code. It does work. I'm also on a MacOS 10.15.5 using Pycharm:
image

The only difference seems to be Python version, which I've used 3.7.6, but this would not make that difference.

Regarding the end_line, that is an implementation detail, necessary to create animations, \r is mandatory to enable printing on top of the same text very fast, to give the impression of moving things.

Anyway, keep me posted, let's try to figure this out.

@rsalmei
Copy link
Owner

rsalmei commented Jun 24, 2020

Oh, regarding the terminal, in there it should work!
Do you use iTerm2? If not I recommend it very much, it is much more advanced.

Anyway, the bar only soft wraps if there's no space for a full line, the terminal wraps automatically. Try to increase the Terminal a little.
Another thing, you could pass length=20 to decrease the alive_bar size.

Regarding the animated gifs, yeah, pypi doesn't fit them. Please always use the main page in: https://github.com/rsalmei/alive-progress
The pypi page is only updated on releases, and the main page gets updated much more regularly.

@diogomreiras
Copy link
Author

@rsalmei
Thanks for your reply.
I can run it correctly as you did on the Python Console of PyCharm, and on the normal Terminal outside of PyCharm.
However on the Terminal outside of PyCharm it only behaves normally if the window size is larger then 80 char and the default is 80 wide (80x24 to be exact). So fails by 1 char since the eta uses 2 digits on the beginning.

However, running the file through the PyCharm option "Run 'main'" (right clicking on the file inside PyCharm) (I don't know how to describe it better!), where main.py is a file with the previous code, then PyCharm's Run tab (next to Python Console tab) still has the behaviour I described before.

@rsalmei
Copy link
Owner

rsalmei commented Jun 26, 2020

Hey, you can configure globally for the alive_bar to be smaller, use:

from alive_progress import config_handler
config_handler.set_global(length=20)

What does that Pycharm's "Run 'main'" function do differently? Why wouldn't it work in there?

@diogomreiras
Copy link
Author

diogomreiras commented Jul 1, 2020

@rsalmei :

What does that Pycharm's "Run 'main'" function do differently? Why wouldn't it work in there?

I am no PyCharm expert. I have no idea...
Is there anything I can do to help you somehow fix this?

@rsalmei
Copy link
Owner

rsalmei commented Jul 3, 2020

I can run it correctly as you did on the Python Console of PyCharm, and on the normal Terminal outside of PyCharm.

So it does work in both pycharm and terminal, great.
It is not working only via "Run main" function, I'm gonna try to simulate that.

@rsalmei rsalmei changed the title alive_bar not working properly on PyCharm and Terminal on Mac alive_bar not working properly on PyCharm's "Run" menu option Jul 3, 2020
@rsalmei
Copy link
Owner

rsalmei commented Jul 3, 2020

Well, I know the pycharm's terminal is heavily instrumented, so maybe it is a bug in there.
I've tested, the "Run" command only calls python main.py. The script works if you run it in the terminal, in the same working directory, but it does not work inside pycharm's. I think we can't do anything about it, just please use it inside pycharm's terminal or in a real terminal.

Regarding the size that soft wraps, please include a length config in alive_bar params for now to reduce it a little. The next release should eventually include a new feature to improve upon that, I'm working on it.

@rsalmei rsalmei closed this as completed Jul 3, 2020
@darkhark
Copy link

darkhark commented Apr 4, 2021

I just came across your tool and was also having issues running in PyCharm's "Run Console". I was able to get it to work using the answer here: https://stackoverflow.com/a/48002833/7658632

with alive_bar(row_num, force_tty=True, bar='filling') as bar:

I hope this helps!

@rsalmei
Copy link
Owner

rsalmei commented Apr 4, 2021

Yes, thanks @darkhark
I wasn't aware of that "Emulate terminal..." option! 👍

@jpcartailler
Copy link

Indeed @darkhark , force_tty=True was the magic sauce for PyCharm (2021.1) - cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants