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

interactive plot window not showing under wayland in debug mode for matplotlib=3.9 #1633

Closed
suxpert opened this issue Jul 22, 2024 · 15 comments
Assignees
Labels
Fixed in next release This issue has been fixed, but won't be available to customers until the next release.

Comments

@suxpert
Copy link

suxpert commented Jul 22, 2024

Environment data

  • debugpy version: 1.8.2
  • OS and version: OpenSUSE Tumbleweed (20240716), KDE Plasma 6 under wayland.
  • Python version (& distribution if applicable, e.g. Anaconda): python 3.11.9 from conda-forge (mamba)
  • Using VS Code or Visual Studio:
    VS Code with Python Debugger v2024.8.0

Actual behavior

Try debugging the following code:

import matplotlib.pyplot as plt

plt.plot([1,2,3,3])
plt.show()
pass

If the break point is at pass, where Debugger skipped entering the interactive mode, the figure is shown normally.
But if there are break points earlier, e.g., add a break point at plt.plot..., then debug and go though until we stop at pass,
the figure won't be shown, with a wayland icon/window showing in the taskbar, but an invisible figure window.

Turing on interactive mode manually makes the plot invisible too (set break point at pass and debug):

import matplotlib.pyplot as plt

plt.ion()
plt.plot([1,2,3,3])
plt.show()
pass

Expected behavior

We expect the interactive plot window be shown as a normal window and response to resize/maximize etc.

Steps to reproduce:

  1. Create an environment with matplotlib=3.9: mamba create -n 'test' matplotlib=3.9 qt-wayland
  2. Enabling wayland support via setting QT_QPA_PLATFORM=wayland;xcb in /etc/environment or launch.json
  3. launch VS code and try debugging the previous code snippets
  4. You may see the behavior described earlier, with visible figure window when interactive mode is off, or misbehavior when interactive mode is on.

Additional information:

  1. If we down-grade matplotlib to 3.8, this issue do not exist. (see Can't create plot from the debug console #1606)
  2. Might be the same issue as Failed test due to matplotlib deprecation of interactive_bk #1623, don't know if is related to Unable to interactively see matplotlib plots with QtAgg backend #858 et al.,
  3. Don't know if this is wayland specific, or also affect X11 (not tested). But note that under wayland, there exists a warning: qt.qpa.wayland: Wayland does not support QWindow::requestActivate() when plt.show().
@rchiodo
Copy link
Contributor

rchiodo commented Jul 22, 2024

There's specific code in pydevd (the base of debugpy) that likely is out of date with matplotlib: https://github.com/fabioz/PyDev.Debugger/blob/54f8db469c2d8c31635db7cc59a10bc8dab76057/pydevd.py#L695

@jcjaskula-aws
Copy link

jcjaskula-aws commented Sep 15, 2024

Proposed this fix: fabioz/PyDev.Debugger#289. Curious to know if it solves most of the issues listed here.

@mariuswallraff
Copy link

Thank you for the proposed fix, sadly it did not help for me. I could not notice any differences (and I verified that I modified the correct file; raising a ValueError led to the expected result).

@planted-jason-hoving
Copy link

same issue here. any updated guidance on how to fix?

I am using python 3.12.1 with up-to-date VS Code for windows, and updated to the latest debugpy 1.8.11

@rchiodo
Copy link
Contributor

rchiodo commented Dec 20, 2024

There's likely a need to update the matplotlib code that pydevd has. This code here:

https://github.com/fabioz/PyDev.Debugger/blob/d0f81de46ec51687ac24ae9598eb2615010a4b44/pydev_ipython/matplotlibtools.py#L93

@rchiodo rchiodo self-assigned this Dec 20, 2024
@dangpzanco
Copy link

I had this same issue with Matplotlib >=3.9 on VSCode debug mode for multiple Python versions.

Running matplotlib.use("QtAgg") before plotting fixed the issue.

It seems to be a problem with the debuggers not interacting correctly with matplotlib anymore, see: matplotlib/matplotlib#28449 (comment)

@rchiodo rchiodo added the Fixed in next release This issue has been fixed, but won't be available to customers until the next release. label Jan 15, 2025
@rchiodo
Copy link
Contributor

rchiodo commented Jan 15, 2025

This issue should be fixed in the latest build of debugpy. It should ship with VS code in a future version of the Python Debugger Extension or you can install your own debugpy from pypi

@rchiodo rchiodo closed this as completed Jan 15, 2025
@rchiodo
Copy link
Contributor

rchiodo commented Jan 15, 2025

Take that back, our release to PyPI failed when it looked like it succeeded. Fix will be coming after we resolve that problem.

@rchiodo rchiodo reopened this Jan 15, 2025
@rchiodo
Copy link
Contributor

rchiodo commented Jan 16, 2025

PyPI release succeeded. v1.8.12 is now available

@rchiodo rchiodo closed this as completed Jan 16, 2025
@planted-jason-hoving
Copy link

planted-jason-hoving commented Jan 16, 2025

Thank you! I can confirm that plots created in a python file (BEFORE hitting a breakpoint and entering debug mode) are appearing and interacting normally. However, I am still not able to create plots from the VSCode Debug Console like I have been able to in previous versions of python/debugpy. The behavior is the same as what's described in the issue - an empty figure window and wayland appears but is "Not responding" and requires terminating python to unfreeze.

Steps to reproduce

import matplotlib.pyplot as plt
x = [0, 1]
y = [0, 2]
pass

Place breakpoint on pass, then in the VSCode Debug Console try to plot
plt.plot(x, y)
Attempts to use plt.show(), plt.figure(), plt.ion() did not work

@rchiodo
Copy link
Contributor

rchiodo commented Jan 16, 2025

How did you update the debugger used by vscode? This fix isn't in VS code yet, you'd have to manually copy debugpy into the extension folder.

@rchiodo
Copy link
Contributor

rchiodo commented Jan 16, 2025

That works for me inside VS code if I manually update the bits it uses.

@planted-jason-hoving
Copy link

Ah, gotcha. I had simply updated the debugpy dependency in my project env (using poetry).

I now have replaced the %USERPROFILE%\.vscode\extensions\ms-python.debugpy-2024.14.0-win32-x64\bundled\libs\debugpy\ directory with the package that had gotten installed in my project env and everything seems to be working well. Thanks again!

@yamichael
Copy link

I tried to replicate this solution on VSCode on Ubuntu 20.04
I replaced the debugpy in the extension folder to 1.8.12 here:
~/.vscode/extensions/ms-python.debugpy-2024.14.0-linux-x64/bundled/libs/debugpy
I made sure it uses it by printing the module path and version while in debug mode:

from matplotlib import pyplot as plt
import debugpy
import os


def main():
    print(os.path.abspath(debugpy.__path__[0]))
    print(debugpy.__version__)
    pass


if __name__ == '__main__':
    main()

while on breakpoint on pass, I am still unable to plot graphs in interactive mode.

Did I miss anything?

@rchiodo
Copy link
Contributor

rchiodo commented Jan 21, 2025

That sounds like it should work. It should print out something like this on the command line:

Backend tkagg is interactive backend. Turning interactive mode on.

If that didn't happen, then debugpy didn't detect matplotlib being used. Your exact code works fine for me. I just do this in the debug console:

plt.plot()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in next release This issue has been fixed, but won't be available to customers until the next release.
Projects
None yet
Development

No branches or pull requests

7 participants