microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python
https://pypi.org/project/debugpy/
Other
1.8k stars 131 forks source link

qt_loaders.py uses the removed imp module (Python 3.12) #1531

Open ondrudav opened 6 months ago

ondrudav commented 6 months ago

Environment data

Actual behavior

Pydevd runs into an exception when enabling matplotlib interactive mode for Qt5 backend.

Failed to enable GUI event loop integration for 'qt'
Traceback (most recent call last):
  File "c:\Users\Z004N92M\.vscode\extensions\ms-python.python-2024.2.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydev_ipython\matplotlibtools.py", line 30, in do_enable_gui    enable_gui(guiname)
  File "c:\Users\Z004N92M\.vscode\extensions\ms-python.python-2024.2.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydev_ipython\inputhook.py", line 540, in enable_gui        
    return gui_hook(app)
           ^^^^^^^^^^^^^
  File "c:\Users\Z004N92M\.vscode\extensions\ms-python.python-2024.2.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydev_ipython\inputhook.py", line 176, in enable_qt
    from pydev_ipython.qt_for_kernel import QT_API, QT_API_PYQT5
  File "c:\Users\Z004N92M\.vscode\extensions\ms-python.python-2024.2.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydev_ipython\qt_for_kernel.py", line 116, in <module>      
    QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)
                                   ^^^^^^^^^^^^^^^^^
  File "c:\Users\Z004N92M\.vscode\extensions\ms-python.python-2024.2.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydev_ipython\qt_loaders.py", line 276, in load_qt
    if not can_import(api):
           ^^^^^^^^^^^^^^^
  File "c:\Users\Z004N92M\.vscode\extensions\ms-python.python-2024.2.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydev_ipython\qt_loaders.py", line 152, in can_import       
    if not has_binding(api):
           ^^^^^^^^^^^^^^^^
  File "c:\Users\Z004N92M\.vscode\extensions\ms-python.python-2024.2.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\pydev_ipython\qt_loaders.py", line 115, in has_binding      
    import imp
ModuleNotFoundError: No module named 'imp'
Backend QtAgg is interactive backend. Turning interactive mode on.

Expected behavior

Interactive mode is turned on without printing a traceback.

Steps to reproduce:

  1. Install matplotlib 3.8.3, PyQt5 5.15.10 and setuptools 69.1.1
  2. Debug this script with a breakpoint on the print call:
    import matplotlib
    print()
luyun1 commented 4 months ago

Hello, following your instructions, I reinstalled matplotlib 3.8.3, PyQt5 5.15.10 and setuptools 69.1.1. However, I still made the above error. Here is my error message. Could you please provide me with some relevant guidance? I would really appreciate it. OS: Windows 11 Python version: 3.12.2 IDE: Pycharm 2024.1 Snipaste_2024-04-11_18-08-24

Error: Failed to enable GUI event loop integration for 'qt' Traceback (most recent call last): import imp ModuleNotFoundError: No module named 'imp' Backend QtAgg is interactive backend. Turning interactive mode on.

Jenia-Trullion commented 1 month ago

To support python 3.12 you should change the code in:_vendored/pydevd/_pydevd_bundle/pydevd_utils.py from spec = spec_from_file_location('__main__', file, loader=loader) m = module_from_spec(spec) sys.modules['__main__'] = m return m to ` spec = importlib.util.spec_from_loader('main', loader=None) m = importlib.util.module_from_spec(spec)

Assign the new module to sys.modules['main']

sys.modules['__main__'] = m
return m`
luyun1 commented 1 month ago

邮件已收到~~勿念