Skip to content

Debugger crashes when importing matplotlib with justMyCode set to false #758

@noamgot

Description

@noamgot

Environment data

  • Python Debugger version: 2025.6.0
  • debugpy version: 1.8.13
  • OS and version: Window 11, connected with SSH to Ubuntu 22.04.3 LTS (the code runs on the Linux machine)
  • Environment: pixi (conda) environment with python 3.10
  • IDE: Cursur v.1.2.4 (VSCode 1.99.3)

Actual behavior

When trying to debug a code that imports matplotlib with justMyCode set to false (in my user settings), I get this error:

Traceback (most recent call last):
  File "_pydevd_bundle\\pydevd_cython.pyx", line 1090, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch
  File "_pydevd_bundle\\pydevd_cython.pyx", line 494, in _pydevd_bundle.pydevd_cython.PyDBFrame.do_wait_suspend
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 2188, in do_wait_suspend
    keep_suspended = self._do_wait_suspend(thread, frame, event, arg, trace_suspend_type, from_this_thread, frames_tracker)
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 2214, in _do_wait_suspend
    self._activate_gui_if_needed()
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 1676, in _activate_gui_if_needed
    activate_function()
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 1659, in <lambda>
    "matplotlib": lambda: activate_matplotlib(do_enable_gui),
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py", line 138, in activate_matplotlib
    gui, backend = find_gui_and_backend()
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py", line 64, in find_gui_and_backend
    backend = matplotlib.rcParams["backend"]
AttributeError: partially initialized module 'matplotlib' has no attribute 'rcParams' (most likely due to a circular import)
Traceback (most recent call last):
  File "$USER/project/.pixi/envs/default/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "$USER/project/.pixi/envs/default/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 71, in <module>
    cli.main()
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 501, in main
    run()
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 351, in run_file
    runpy.run_path(target, run_name="__main__")
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 310, in run_path
    return _run_module_code(code, init_globals, run_name, pkg_name=pkg_name, script_name=fname)
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 127, in _run_module_code
    _run_code(code, mod_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 118, in _run_code
    exec(code, run_globals)
  File "$USER/.cursor-server/data/User/globalStorage/buenon.scratchpads/scratchpads/587806bd8d2d5e49dde1948c853676a7/scratch9.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "$USER/project/.pixi/envs/default/lib/python3.10/site-packages/matplotlib/__init__.py", line 1, in <module>
    """
  File "$USER/project/.pixi/envs/default/lib/python3.10/site-packages/matplotlib/__init__.py", line 1, in <module>
    """
  File "_pydevd_bundle\\pydevd_cython.pyx", line 1697, in _pydevd_bundle.pydevd_cython.SafeCallWrapper.__call__
  File "_pydevd_bundle\\pydevd_cython.pyx", line 634, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch
  File "_pydevd_bundle\\pydevd_cython.pyx", line 1112, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch
  File "_pydevd_bundle\\pydevd_cython.pyx", line 1090, in _pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch
  File "_pydevd_bundle\\pydevd_cython.pyx", line 494, in _pydevd_bundle.pydevd_cython.PyDBFrame.do_wait_suspend
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 2188, in do_wait_suspend
    keep_suspended = self._do_wait_suspend(thread, frame, event, arg, trace_suspend_type, from_this_thread, frames_tracker)
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 2214, in _do_wait_suspend
    self._activate_gui_if_needed()
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 1676, in _activate_gui_if_needed
    activate_function()
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py", line 1659, in <lambda>
    "matplotlib": lambda: activate_matplotlib(do_enable_gui),
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py", line 138, in activate_matplotlib
    gui, backend = find_gui_and_backend()
  File "$USER/.cursor-server/extensions/ms-python.debugpy-2025.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py", line 64, in find_gui_and_backend
    backend = matplotlib.rcParams["backend"]
AttributeError: partially initialized module 'matplotlib' has no attribute 'rcParams' (most likely due to a circular import)

Re-setting justMyCode to true allows me to debug (but without stepping into other libraries' code, as I wish to do in many times)

Expected behavior

I wish I could avoid this error 😄

Steps to reproduce:

  1. make sure that justMyCode set to false (e.g, in the user settings)
  2. run this example code I simply pressed the small debugging icon at the top right (Python Debugger: Debug python file):
import matplotlib.pyplot as plt
import numpy as np

# Generate some data
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)

# Create the plot
plt.plot(x, y, label='sin(x)')
plt.title('Simple Sine Wave')
plt.xlabel('x')
plt.ylabel('sin(x)')
plt.legend()
plt.grid(True)
plt.show()

thanks!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions