PyDev.Debugger

3.5.0 · active · verified Sun Apr 12

PyDev.Debugger is a powerful Python debugger primarily known for its integration with IDEs such as PyDev (Eclipse), PyCharm, and VSCode Python (via debugpy). It allows for seamless remote debugging of Python applications running in various environments. The library is actively maintained, with regular updates to support new Python versions and enhance performance, including fast tracing with `sys.monitoring` for Python 3.12+. The current stable version is 3.5.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initiate remote debugging. Run this script, then start your IDE's remote debug server (e.g., 'Python Debug Server' in PyCharm or 'Attach' configuration in VSCode with PyDev for VSCode extension). The script will pause at `settrace` (if `suspend=True`) or continue until a breakpoint is hit. Ensure `PYDEVD_REMOTE_HOST` and `PYDEVD_REMOTE_PORT` environment variables match your IDE's debug server configuration.

import pydevd
import os

# Configure host and port for your IDE's debug server
# The host should be the IP address or hostname where your IDE is running.
# The port should match the port configured in your IDE's debug server.
# For local debugging, 'localhost' or '127.0.0.1' is common.
# Ensure these environment variables are set in your execution environment
# or replace with literal values for quick testing.

IDE_HOST = os.environ.get('PYDEVD_REMOTE_HOST', '127.0.0.1')
IDE_PORT = int(os.environ.get('PYDEVD_REMOTE_PORT', '5678')) # Common default port

print(f"Connecting PyDev.Debugger to {IDE_HOST}:{IDE_PORT}...")

try:
    # This line connects the Python process to the remote debugger server.
    # Execution will pause here until the IDE connects.
    pydevd.settrace(host=IDE_HOST, port=IDE_PORT, suspend=False, stdoutToServer=True, stderrToServer=True)
    print("Debugger connected. You can now set breakpoints in your IDE.")
except Exception as e:
    print(f"Could not connect to debugger: {e}")

def main():
    message = "Hello, remote debugging!"
    print(message)
    # Place a breakpoint here in your IDE after connecting
    result = "Debugging complete."
    print(result)

if __name__ == '__main__':
    main()

view raw JSON →