{"id":3227,"library":"pydevd-pycharm","title":"PyCharm Debugger (pydevd-pycharm)","description":"pydevd-pycharm is the Python debugger backend used by JetBrains PyCharm and IntelliJ IDEA. It facilitates debugging Python applications, including remote debugging, stepping through code, and inspecting variables. The library is actively maintained and updated frequently, typically in sync with PyCharm and IDEA releases, with versions like '261.23567.35' reflecting internal build numbers.","status":"active","version":"261.23567.35","language":"en","source_language":"en","source_url":"https://github.com/JetBrains/intellij-community","tags":["debugger","ide","pycharm","remote-debugging","jetbrain"],"install":[{"cmd":"pip install pydevd-pycharm","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"While PyCharm often simplifies to 'import pydevd', the explicit path 'from pydevd_pycharm.pydevd import settrace' is more reliable for direct pip installations as 'pydevd' might not be a top-level module.","wrong":"import pydevd; pydevd.settrace(...)","symbol":"settrace","correct":"from pydevd_pycharm.pydevd import settrace"}],"quickstart":{"code":"import os\nfrom pydevd_pycharm.pydevd import settrace\n\n# Configure PyCharm for remote debugging first (Run -> Edit Configurations -> Python Remote Debug).\n# Get the host and port from your PyCharm setup.\n# The host should be the IP address of the machine running PyCharm (e.g., your local machine's IP).\n# The port is what PyCharm is listening on (e.g., 51235).\n\nPYCHARM_DEBUG_HOST = os.environ.get('PYCHARM_DEBUG_HOST', 'localhost')\nPYCHARM_DEBUG_PORT = int(os.environ.get('PYCHARM_DEBUG_PORT', '51235')) # Check PyCharm config for actual port\n\nprint(f\"Attempting to connect to PyCharm debugger at {PYCHARM_DEBUG_HOST}:{PYCHARM_DEBUG_PORT}...\")\n\ntry:\n    # suspend=False means the program will not wait for the debugger connection at this point.\n    # settrace() will attempt to connect and continue execution if it fails.\n    settrace(\n        host=PYCHARM_DEBUG_HOST,\n        port=PYCHARM_DEBUG_PORT,\n        suspend=False, # Set to True if you want execution to pause until debugger connects\n        stdoutToServer=True,\n        stderrToServer=True\n    )\n    print(\"Debugger connection established (or attempted).\")\nexcept Exception as e:\n    print(f\"Failed to connect to debugger: {e}\")\n\n# Your application logic continues here\ndef my_function():\n    message = \"This line can be a breakpoint in PyCharm.\"\n    print(message)\n    return message\n\nif __name__ == '__main__':\n    my_function()","lang":"python","description":"This example demonstrates how to set up remote debugging with `pydevd-pycharm`. It instructs the Python process to connect to a PyCharm debugger server running on a specified host and port. This is typically used when debugging code running in a separate environment (e.g., a Docker container, remote server) from your PyCharm IDE. Ensure your PyCharm IDE is configured to listen for remote debug connections on the specified host and port."},"warnings":[{"fix":"Only install this package directly if you are setting up remote debugging and need to inject the debugger client into an environment. Otherwise, rely on your PyCharm installation.","message":"Most users do not need to install `pydevd-pycharm` manually via pip. PyCharm bundles and manages its own version internally. Manual installation is primarily for remote debugging scenarios where the target environment (e.g., a server, Docker container) does not have PyCharm installed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the `pydevd-pycharm` version installed in your remote environment is compatible with your PyCharm IDE version. Typically, upgrading `pydevd-pycharm` in your remote environment to match your IDE's recent version is the solution.","message":"The internal communication protocol and API parameters for `settrace` can change between major PyCharm/IDEA releases. An older `pydevd-pycharm` client might not be fully compatible with a newer PyCharm IDE, and vice-versa, leading to debugging issues or failures to connect.","severity":"breaking","affected_versions":"All versions, especially across major PyCharm IDE releases."},{"fix":"Verify that your PyCharm IDE is listening on the correct host/port. Ensure there are no firewalls blocking traffic between the debugged application and the IDE. Use the actual IP address of the PyCharm machine, not 'localhost', if they are on different machines or within Docker networks.","message":"Remote debugging requires careful network configuration. Firewall rules, network access control lists (ACLs), or incorrect IP addresses/ports can prevent the debugger client from connecting to the PyCharm IDE. Common issues include 'Connection refused' or 'Timeout' errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Disable debugger features that are not strictly needed (e.g., `stdoutToServer`, `stderrToServer` if console output isn't critical to debug) or remove `settrace` calls entirely for production environments. Only debug when necessary.","message":"Running code under a debugger, especially with `stdoutToServer=True` or `stderrToServer=True`, can introduce noticeable performance overhead. This is generally expected for debugging tools but can be significant in performance-critical applications.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}