PyCharm 2019.3.3 (professional edition) : different output when running script or executing it in console

Hi,

I noticed some really weird behaviour and would like to know if anyone has a hint about what is happening.

I've got a python script written in a .py file, which I am able to properly run without any problems from both the terminal and PyCharm. However, when trying to execute it in the Python console via PyCharm, I get an error and the process finishes.

Note that I tried executing the code in an IPython console opened from the terminal, and everything went fine (no error). What is even weirder, is that if I debug the script without setting any breakpoint I do not get any error, but if I however set a breakpoint at the line producing the error, and then step over or resume the program, I get the error.

The code I'm using is quite short and simple, as it is an example drawn from the documentation of the pymesh package.

>>> vertices = np.array([
...     [0.0, 0.0],
...     [1.0, 0.0],
...     [1.0, 1.0],
...     [0.0, 1.0],
...     ]);
>>> tri = pymesh.triangle();
>>> tri.points = vertices;
>>> tri.max_area = 0.05;
>>> tri.split_boundary = False;
>>> tri.verbosity = 0;
>>> tri.run();

and the error is "Maximum area must be greater than zero".

I know this is likely to be due to the package itself, but isn't it weird that running and executing in the console result in two different outputs, and that even though the interpreter I am using in this project is the same as the one which is used when calling Python or IPython from the terminal, the output produced is different ?

My OS is Ubuntu 18.04, and I'm using PyCharm professional edition for Anaconda 2019.3.3.

Thanks in advance for any help !

0
4 comments

I'm not sure how you installed pymesh, but I've tried to reproduce it using Docker image https://pymesh.readthedocs.io/en/latest/installation.html#docker , and creating project interpreter based on this docker image - your code run without errors from the python console.

Could you try this as well?

1
Avatar
Permanently deleted user

I also got the same result using the Docker image. I hence tried to rebuild and reinstall the package locally, and managed to run the code without errors from the console as well.

In fact I noticed I was not exactly running the example code: I have an additional matplotlib.pyplot import statement at the beginning (I wanted to use it to plot the triangulation). Without this import statement, everything is fine. But with this statement included, I am able to run the script but not execute the code in the console. This is really surprising ...

EDIT : turns out checking "Show plots in tool window" in Settings/Tools/Python Scientific does the trick. In my opinion, the bug is likely due to the fact any matplotlib.pyplot statement without this option turned on yields a "Backend Qt5Agg is interactive backend. Turning interactive mode on."

I would really like to know why this happens. I tried to switch matplotlib backend to TkAgg as advised in https://stackoverflow.com/questions/40963074/pycharm-importing-matplotlib but the message is still the same for me ("Backend Qt5Agg..." and not "Backend TkAgg...") ...

0

>the bug is likely due to the fact any matplotlib.pyplot statement without this option turned on yields a "Backend Qt5Agg is interactive backend. Turning interactive mode on."

When you run a script that generates a plot without this option - matplotlib tries to launch it's own GUI. Are you able to see plots when running from the terminal?

0
Avatar
Permanently deleted user

Yes I am (thanks again for your interest in my problem) !

0

Please sign in to leave a comment.