PyDev.Debugger
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
- breaking PyDev.Debugger versions are often tied to specific Python versions. Latest 3.x versions (e.g., 3.5.0) require Python 3.8 and onwards. For Python 3.3 to 3.7, use `pydevd==2.10.0`. For Python 2, use `pydevd==2.8.0`. Installing an incompatible version can lead to runtime errors.
- gotcha It is generally not recommended to install `pydevd` separately if you are using an IDE (like PyDev for Eclipse, PyCharm, or VSCode Python with `debugpy`) that already bundles or manages its debugger backend. Manual installation is primarily for remote debugging scenarios where the target machine does not have the IDE's bundled helper files, and can lead to version conflicts or unexpected behavior if mismatched with the IDE's internal debugger version.
- deprecated Some parameters to `pydevd.settrace()` (or `pydevd_pycharm.settrace()`) like `stdoutToServer` or `stderrToServer` have undergone renaming in newer versions to be more 'Pythonic'. Using older parameter names with a newer `pydevd` version can result in errors.
- breaking The standalone `pydevd` library (fabioz/PyDev.Debugger) and the `pydevd` version vendored within Microsoft's `debugpy` (used by VSCode Python and Visual Studio Python) have diverged significantly since `debugpy` version 1.8.1. This means that installing a recent standalone `pydevd` might not be compatible with `debugpy`'s expectations, potentially breaking debugging functionality for VSCode/Visual Studio users.
Install
-
pip install pydevd
Imports
- settrace
import pydevd pydevd.settrace(host='<IDE_HOST>', port=<IDE_PORT>)
Quickstart
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()