"When using PyCharm (regardless of the version) in debug mode or starting matplotlib.pyplot.plot in the Python console, the process completely freezes, and I can only force it to end."
Have you tried another backend, say matplotlib.use("qtagg")?
Have you tried to create a new environment? Does it happen there as well?
Replay:
"freeze" is hard to debug.
Yes you are right. It's very hard to debug. I tried many methods to solve this.
Finally I found it happens only when I upgraded matplotlib==3.9.* and use [debug] or [python console] mode with pycharm(any version of this).
So I have to solve this problem by re-install matplotlib==3.8.*.
When you terminate it, do you get a stacktrace?
When I terminate it, there is no error message raised in python process.
Messages appear in console are as following:
Backend tkagg is interactive backend. Turning interactive mode on.
Process finished with exit code -805306369 (0xCFFFFFFF)
Have you tried another backend, say matplotlib.use("qtagg")?
Yes I do. I tried other backends but useless.
qtagg: I have no idea what this performs. Sometimes it is available, but sometimes performs like tkagg and completely freezes.
qt5agg: I tried it sometimes before but it returns some error message in python process. I tried it again just now and it seems ok.
agg: It is ok but can not help me to show image info intime.
wxagg: It performs like tkagg and completely freezes.
Have you tried to create a new environment? Does it happen there as well?
I did not try to create a new enviroment. Actually I coding in both MyPC[win-10] and CompanyServer[Kali-linux-2022] while finding the same error. Both the python versions are 3.9.*.
Due to the characteristics of the problem(Only when I use pycharm[debug] mode or pycharm[python console] mode), I tried update my pycharm with versions from 2022.3.1 to 2024.2.3, but none of them made sense.
We would need more details than this. Presumably your install needs to be redone and there is not much we can do.
Sorry for my late reply. I have provided a detailed explanation of the situation I encountered in my previous response. I am not sure what other information needs to be provided, thank you very much for your reply!
Another point for measure: I can run the program on RHEL8 with PyCharm Community 2024.1.4 (using Matplotlib 3.9 from source, but I doubt it is related to that).
Just to be sure: the program runs OK from a Python shell? So it is only PyCharm that is the problem?
I have the same issue that @name-used describes.
In short: I plot anything with matplotlib 3.9.2 in the PyCharm console, a figure pops up, but does not respond. If I click anywhere in this picture then after a while I get the message in Pycharm: Process finished with exit code -805306369 (0xCFFFFFFF)
There is no stacktrace.
The code I used to plot anything and to reproduce the problem is:
In response to @oscargus, the problem seems to occur when using the PyCharm console. Running the code normally in PyCharm works fine. Also when I start a console in a Powershell and then run the code, it works fine.
When I start to run the code in a Pycharm Python Console, the mentioned issue arises. Adding plt.ion() and/or plt.pause(0.1) does not change this.
If I type plt.show(block=True) in console, however, the plot does work and responds properly, but this is not a workable solution as I want to work in the console to interactively analyze data.
Adding the IPython package does not fix the problem either.
Python version
I reinstalled new environments many times, both with python 3.11.7 and 3.12.6. In both versions the issue persists.
Backends
I only installed matplotlib 3.9.2 in these environments; no other packages.
print(f"Python {sys.version},\nMatplotlib {matplotlib.__version__} with backend {matplotlib.get_backend()}")
results in:
Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)],
Matplotlib 3.9.2 with backend tkagg
If I then install PyQt5 and use this backend, I still have the same issue.
vers = ['%s = %s' % (k,v) for k,v in vars(PyQt5.Qt).items() if k.lower().find('version') >= 0 and not inspect.isbuiltin(v)]
print(f"Python {sys.version},\nMatplotlib {matplotlib.__version__} with backend {matplotlib.get_backend()}")
print('\n'.join(sorted(vers)))
As @jklymak suggested, I tested TKinter via the PyCharm terminal with:
.\.venv\Scripts\python.exe -c "from tkinter import Tk; Tk().mainloop()"
and this worked properly.
Same for PyQt5:
.\.venv\Scripts\python.exe -c "from PyQt5.QtWidgets import *; app = QApplication([]); win = QMainWindow(); win.show(); app.exec()"
This also works perfectly fine.
Pycharm version
I am working in the PyCharm 2024.2.3 python console.
Workable solution
As @name-used, already mentioned, matplotlib 3.8.x does seem to work as it should, so for now I will continue using this version.
Is this a PyCharm of matplotlib bug? I hope I was able to provide some hints that could pinpoint the problem of these issues. Let me know if anyone would like to receive more information about my setup.
I don't know how pycharm console is meant to work, but can you directly try running the hello-world examples without calling python.exe?
That 3.8 works, but 3.9 does not is interesting, but that everything works except in pycharm console makes it seem the issue is there, perhaps surfaced by one of our changes.
However, I'm confused what is causing this - we became more permissive, but PyCharm expects "TkAgg" and we have allowed the user to call "tkagg"? That failed before, but now works? Or is the change that get_backend now returns what the user put in, not the canonical name?
This could well be a duplicate of #28449, meaning that PyCharm need to support the changes in backend registration introduced in Matplotlib 3.9.0.
It seems that as described in this question, there will be an error when I use 'tkagg', but if I use the exact uppercase and lowercase letters' TkAgg ', there will be no error.
Thank you very much for providing the reference!
Thanks too. @jklymak@jensravesloot
This problem seems could be sovled by typing 'TkAgg' instead of 'tkagg'.
It's such an unanticipated solution.
Another point for measure: I can run the program on RHEL8 with PyCharm Community 2024.1.4 (using Matplotlib 3.9 from source, but I doubt it is related to that).
Just to be sure: the program runs OK from a Python shell? So it is only PyCharm that is the problem?
It would be all ok in pycharm python-run-mode. Only in "pycharm inline-mode", it would come to a bug.
The "pycharm inline-mode" includes:
When running with pycharm python-debug-mode and stop at any breakpoint, type codes in debug-console and run plt.show().
Open the pycharm-python-console. Directly type codes in pycharm-python-console and run plt.show().
The more I try, the more I start to believe this is indeed a bug on PyCharm's side.
Indeed. PyCharm and similar need to support the changes made in #27948, in particular the first item about backend names being case-insensitive. Until that happens Matplotlib code that is valid in say JupyterLab will not necessarily be valid in PyCharm.
I think we should close this issue as it is really a duplicate of #28449
Activity
jklymak commented on Sep 29, 2024
We would need more details than this. Presumably your install needs to be redone and there is not much we can do.
timhoffm commented on Sep 29, 2024
"freeze" is hard to debug.
name-used commented on Sep 30, 2024
Replay:
Yes you are right. It's very hard to debug. I tried many methods to solve this.
Finally I found it happens only when I upgraded matplotlib==3.9.* and use [debug] or [python console] mode with pycharm(any version of this).
So I have to solve this problem by re-install matplotlib==3.8.*.
When I terminate it, there is no error message raised in python process.
Messages appear in console are as following:
Yes I do. I tried other backends but useless.
qtagg: I have no idea what this performs. Sometimes it is available, but sometimes performs like tkagg and completely freezes.
qt5agg: I tried it sometimes before but it returns some error message in python process. I tried it again just now and it seems ok.
agg: It is ok but can not help me to show image info intime.
wxagg: It performs like tkagg and completely freezes.
I did not try to create a new enviroment. Actually I coding in both MyPC[win-10] and CompanyServer[Kali-linux-2022] while finding the same error. Both the python versions are 3.9.*.
Due to the characteristics of the problem(Only when I use pycharm[debug] mode or pycharm[python console] mode), I tried update my pycharm with versions from 2022.3.1 to 2024.2.3, but none of them made sense.
name-used commented on Sep 30, 2024
Sorry for my late reply. I have provided a detailed explanation of the situation I encountered in my previous response. I am not sure what other information needs to be provided, thank you very much for your reply!
oscargus commented on Sep 30, 2024
Another point for measure: I can run the program on RHEL8 with PyCharm Community 2024.1.4 (using Matplotlib 3.9 from source, but I doubt it is related to that).
Just to be sure: the program runs OK from a Python shell? So it is only PyCharm that is the problem?
jklymak commented on Sep 30, 2024
If your problem is just tkagg please check that it works at all in pycharm by running a hello world program. https://matplotlib.org/stable/users/explain/figure/backends.html#debugging-the-figure-windows-not-showing both in pycharm and in a terminal.
jensravesloot commented on Oct 2, 2024
I have the same issue that @name-used describes.
In short: I plot anything with matplotlib 3.9.2 in the PyCharm console, a figure pops up, but does not respond. If I click anywhere in this picture then after a while I get the message in Pycharm: Process finished with exit code -805306369 (0xCFFFFFFF)
There is no stacktrace.
The code I used to plot anything and to reproduce the problem is:
Terminal vs console
In response to @oscargus, the problem seems to occur when using the PyCharm console. Running the code normally in PyCharm works fine. Also when I start a console in a Powershell and then run the code, it works fine.
When I start to run the code in a Pycharm Python Console, the mentioned issue arises. Adding plt.ion() and/or plt.pause(0.1) does not change this.
If I type plt.show(block=True) in console, however, the plot does work and responds properly, but this is not a workable solution as I want to work in the console to interactively analyze data.
Adding the IPython package does not fix the problem either.
Python version
I reinstalled new environments many times, both with python 3.11.7 and 3.12.6. In both versions the issue persists.
Backends
I only installed matplotlib 3.9.2 in these environments; no other packages.
print(f"Python {sys.version},\nMatplotlib {matplotlib.__version__} with backend {matplotlib.get_backend()}")
results in:
Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)],
Matplotlib 3.9.2 with backend tkagg
If I then install PyQt5 and use this backend, I still have the same issue.
vers = ['%s = %s' % (k,v) for k,v in vars(PyQt5.Qt).items() if k.lower().find('version') >= 0 and not inspect.isbuiltin(v)] print(f"Python {sys.version},\nMatplotlib {matplotlib.__version__} with backend {matplotlib.get_backend()}") print('\n'.join(sorted(vers)))results in
As @jklymak suggested, I tested TKinter via the PyCharm terminal with:
.\.venv\Scripts\python.exe -c "from tkinter import Tk; Tk().mainloop()"
and this worked properly.
Same for PyQt5:
.\.venv\Scripts\python.exe -c "from PyQt5.QtWidgets import *; app = QApplication([]); win = QMainWindow(); win.show(); app.exec()"
This also works perfectly fine.
Pycharm version
I am working in the PyCharm 2024.2.3 python console.
Workable solution
As @name-used, already mentioned, matplotlib 3.8.x does seem to work as it should, so for now I will continue using this version.
Is this a PyCharm of matplotlib bug? I hope I was able to provide some hints that could pinpoint the problem of these issues. Let me know if anyone would like to receive more information about my setup.
jklymak commented on Oct 2, 2024
I don't know how pycharm console is meant to work, but can you directly try running the hello-world examples without calling python.exe?
That 3.8 works, but 3.9 does not is interesting, but that everything works except in pycharm console makes it seem the issue is there, perhaps surfaced by one of our changes.
ianthomas23 commented on Oct 2, 2024
This could well be a duplicate of #28449, meaning that PyCharm need to support the changes in backend registration introduced in Matplotlib 3.9.0.
jklymak commented on Oct 2, 2024
Agree this seems the same.
However, I'm confused what is causing this - we became more permissive, but PyCharm expects "TkAgg" and we have allowed the user to call "tkagg"? That failed before, but now works? Or is the change that get_backend now returns what the user put in, not the canonical name?
jensravesloot commented on Oct 2, 2024
Could it also be related to this issue?
https://youtrack.jetbrains.com/issue/PY-52430/matplotlib-figures-get-frozen-when-executed-from-ipython-console
name-used commented on Oct 12, 2024
It seems that as described in this question, there will be an error when I use 'tkagg', but if I use the exact uppercase and lowercase letters' TkAgg ', there will be no error.
Thank you very much for providing the reference!
Thanks too. @jklymak @jensravesloot
This problem seems could be sovled by typing 'TkAgg' instead of 'tkagg'.
It's such an unanticipated solution.
name-used commented on Oct 12, 2024
It would be all ok in pycharm python-run-mode. Only in "pycharm inline-mode", it would come to a bug.
The "pycharm inline-mode" includes:
jensravesloot commented on Oct 28, 2024
For the issue I am having I tried the following two pieces of code in the PyCharm console:
import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt print(matplotlib.get_backend()) plt.plot((1, 4, 6)) plt.show()import matplotlib matplotlib.use('tkagg') import matplotlib.pyplot as plt print(matplotlib.get_backend()) plt.plot((1, 4, 6)) plt.show()Both cases yielded the same result, i.e., the plot still crashes.
ianthomas23 commented on Oct 28, 2024
@jensravesloot Have you reported this to PyCharm? What response did you receive?
jensravesloot commented on Oct 28, 2024
@ianthomas23, I think the issue mentioned here is the same: https://youtrack.jetbrains.com/issue/PY-52430/matplotlib-figures-get-frozen-when-executed-from-ipython-console. I replied there mentioning this thread, but so far I don't have a useful reply. The more I try, the more I start to believe this is indeed a bug on PyCharm's side.
ianthomas23 commented on Oct 28, 2024
Indeed. PyCharm and similar need to support the changes made in #27948, in particular the first item about backend names being case-insensitive. Until that happens Matplotlib code that is valid in say JupyterLab will not necessarily be valid in PyCharm.
I think we should close this issue as it is really a duplicate of #28449