When debugging a script on ubuntu, matplotlib uses a non-interactive backend and won't show plots
已回答
I have a script with:
```
import matplotlib
from matplotlib import pyplot as plt
print(f'{matplotlib.get_backend()}')
plt.plot([1, 2], [2, 5])
plt.show()
```
When I run the script, it prints `module://backend_interagg` and displays the plot. When I debug it, it prints `agg` and then `FigureCanvasAgg is non-interactive, and thus cannot be shown`.
I had no problems displaying plots in debug mode in pycharm on a mac.
It seems similar to this bug, but adding `DISPLAY=True` to my environment variables didn't make any difference:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000143610-Problems-with-Interactive-Plotting-in-Debug-Mode-in-PyCharm-Version-2017-1
请先登录再写评论。
Reproduced on our side. The trigger is the debugpy debugger backend, not Ubuntu and not DISPLAY.
Filed as PY-91227, you can follow it there: https://youtrack.jetbrains.com/issue/PY-91227
When PyCharm launches your script through debugpy it doesn't pass its own plots backend along, so pycharm_matplotlib_backend never reaches PYTHONPATH and matplotlib picks a backend on its own.
On a Mac that's macosx, which is interactive, so the plot appears and nothing looks broken. Your Ubuntu interpreter has no GUI toolkit to fall back to, so it lands on agg. Run mode doesn't involve the debugger, which is why it still prints module://backend_interagg.
Until that's fixed, switch the backend back to pydevd in Settings | Python | Debugger. If you're on 2026.2, debugpy became the default there, which is probably how you ended up on it without changing anything.