Debugpy

raw JSON →
1.8.20 verified Tue May 12 auth: no python install: verified quickstart: stale

debugpy is an implementation of the Debug Adapter Protocol (DAP) for Python, enabling powerful debugging capabilities for various Python applications, including scripts, web apps, and remote processes. It is primarily used to connect Integrated Development Environments (IDEs) like VS Code to a running Python process for features such as setting breakpoints, stepping through code, and inspecting variables. The library is actively maintained, with frequent updates to support new Python versions and fix issues. The current version is 1.8.20.

pip install debugpy
error ModuleNotFoundError: No module named 'debugpy'
cause The 'debugpy' module is not installed in the current Python environment.
fix
Install 'debugpy' using pip: 'pip install debugpy'.
error ImportError: cannot import name 'Literal' from 'typing'
cause The 'Literal' type is not available in Python versions prior to 3.8.
fix
Upgrade to Python 3.8 or later, or avoid using 'Literal' in your code.
error ImportError: cannot import name 'module_from_spec' from 'importlib.util'
cause The 'module_from_spec' function is not available in Python versions prior to 3.5.
fix
Upgrade to Python 3.5 or later, or refactor code to avoid using 'module_from_spec'.
error AttributeError: 'module' object has no attribute 'model'
cause Circular imports or incorrect module paths can lead to this error.
fix
Check for circular imports and ensure module paths are correctly set.
error ImportError: cannot import name 'Node'
cause The 'Node' class or function is not defined or not accessible in the module.
fix
Verify that 'Node' is correctly defined and accessible in the module.
breaking When using VS Code, the `type` field in `launch.json` debug configurations for Python debugging has changed from `"python"` to `"debugpy"`. Older configurations using `"python"` will no longer work with recent versions of the Python Debugger extension.
fix Update your `.vscode/launch.json` file to use `"type": "debugpy"` instead of `"type": "python"` for all Python debug configurations.
breaking debugpy replaced ptvsd as the default remote debugging library in Visual Studio and the Python extension for VS Code. Projects or tutorials referencing `ptvsd` APIs will need to be updated to use `debugpy`.
fix Migrate any `ptvsd` specific code or configurations to use `debugpy` equivalents. For example, replace `ptvsd.enable_attach()` with `debugpy.listen()` or `debugpy.wait_for_client()`.
gotcha Exposing the debug server to all network interfaces by calling `debugpy.listen(('0.0.0.0', port))` can pose a security risk. Anyone on the network who can connect to that port can execute arbitrary code within the debugged process.
fix Only use `'0.0.0.0'` on secure, isolated networks or when specifically required for container/remote debugging setups where network access is controlled. For local debugging, explicitly use `'127.0.0.1'` or omit the host for the default.
gotcha Code executed before `debugpy.listen()` (or before `python -m debugpy --listen...`) cannot be debugged. If you want to debug from the very beginning of your script, you must explicitly call `debugpy.wait_for_client()` immediately after `debugpy.listen()`.
fix Include `debugpy.wait_for_client()` after `debugpy.listen()` to pause execution until your IDE's debugger attaches. This ensures breakpoints set at the start of your script are hit.
gotcha Debugging child processes can be tricky. By default, `debugpy` might not automatically inject itself into subprocesses. Recent versions include fixes, but explicit configuration may still be needed.
fix When launching via CLI, use `--configure-subProcess False` to explicitly ignore subprocesses if not needed, or investigate specific IDE configurations for subprocess debugging. Ensure `debugpy` version 1.8.15 or newer for improved child process handling.
gotcha When debugging remotely, incorrect `pathMappings` in your IDE's launch configuration can prevent breakpoints from being hit or source code from being correctly correlated.
fix Ensure that your IDE's launch configuration (e.g., `.vscode/launch.json`) accurately maps the local project root (`localRoot`) to the remote project root (`remoteRoot`). For example, `"localRoot": "${workspaceFolder}", "remoteRoot": "."` or the specific absolute paths on both sides.
gotcha While debugpy itself supports Python 3.8+, issues have been reported with newer Python versions (e.g., 3.14) requiring specific debugpy fixes. Conversely, debugging older Python versions (e.g., 3.6, 3.7) with current VS Code Python extensions requires installing older, specific versions of the VS Code extensions.
fix Always use a `debugpy` version compatible with your target Python interpreter. If debugging Python <3.8, you might need to use an older VS Code Python extension that bundled an earlier `debugpy` version. Check `debugpy` release notes for specific Python version compatibility and fixes.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.03s 49.0M
3.10 alpine (musl) - - 0.03s 49.0M
3.10 slim (glibc) wheel 2.2s 0.02s 37M
3.10 slim (glibc) - - 0.02s 37M
3.11 alpine (musl) wheel - 0.06s 52.7M
3.11 alpine (musl) - - 0.07s 52.7M
3.11 slim (glibc) wheel 2.3s 0.05s 41M
3.11 slim (glibc) - - 0.05s 41M
3.12 alpine (musl) wheel - 0.06s 44.2M
3.12 alpine (musl) - - 0.06s 44.2M
3.12 slim (glibc) wheel 2.3s 0.06s 35M
3.12 slim (glibc) - - 0.06s 35M
3.13 alpine (musl) wheel - 0.05s 43.9M
3.13 alpine (musl) - - 0.05s 43.8M
3.13 slim (glibc) wheel 2.2s 0.05s 35M
3.13 slim (glibc) - - 0.05s 34M
3.9 alpine (musl) wheel - 0.03s 48.5M
3.9 alpine (musl) - - 0.03s 48.5M
3.9 slim (glibc) wheel 2.7s 0.02s 36M
3.9 slim (glibc) - - 0.03s 36M

This quickstart demonstrates how to integrate `debugpy` into a Python script to enable remote debugging. It sets up a debug server, optionally waits for a client to attach (controlled by `WAIT_FOR_DEBUGGER` environment variable), and includes a programmatic breakpoint. To run: 1. Save as `app.py`. 2. On the remote machine (or local for testing), run `python app.py`. For remote access, ensure `DEBUG_HOST` is set to '0.0.0.0'. 3. In your IDE (e.g., VS Code), configure a 'Python: Remote Attach' launch configuration targeting the specified host and port (default 127.0.0.1:5678). Then start the debugger in your IDE.

import debugpy
import os

# Configuration from environment variables for flexibility
DEBUG_HOST = os.environ.get('DEBUG_HOST', '127.0.0.1')
DEBUG_PORT = int(os.environ.get('DEBUG_PORT', '5678'))
WAIT_FOR_DEBUGGER = os.environ.get('WAIT_FOR_DEBUGGER', 'true').lower() == 'true'

print(f"[*] Debug server attempting to listen on {DEBUG_HOST}:{DEBUG_PORT}")

try:
    debugpy.listen((DEBUG_HOST, DEBUG_PORT))
    print(f"[*] Debug server listening. Host: {DEBUG_HOST}, Port: {DEBUG_PORT}")
    if WAIT_FOR_DEBUGGER:
        print("[*] Waiting for debugger client to attach...")
        debugpy.wait_for_client()
        print("[*] Debugger attached. Continuing program execution.")
    else:
        print("[*] Not waiting for client. Program will continue.")

    # Your application logic starts here
    name = "World"
    message = f"Hello, {name}! This is debugpy in action."
    print(message)
    # Example: A programmatic breakpoint
    debugpy.breakpoint()
    result = 10 * 2
    print(f"Calculated result: {result}")

except Exception as e:
    print(f"[ERROR] Failed to start debug server or an error occurred: {e}")
    import sys
    sys.exit(1)