Skip to content

Instantly share code, notes, and snippets.

@hotohoto
Last active September 16, 2024 02:27
Show Gist options
  • Save hotohoto/ff9f84e069709964c87b99b4d3fee74e to your computer and use it in GitHub Desktop.
Save hotohoto/ff9f84e069709964c87b99b4d3fee74e to your computer and use it in GitHub Desktop.
debugging blender with debugpy

In your Blender script

Wait for a remote debugging client

import debugpy
debugpy.listen(5678)
print("Waiting for debugger attach")
debugpy.wait_for_client()
print("Debugger attached")

...

Or wait only when DEBUG is set

import os
DEBUG = os.environ.get("DEBUG", False)
DEBUG_PORT = 5678

if DEBUG:
    import debugpy
    try:
        debugpy.listen(DEBUG_PORT)
    except RuntimeError as e:
        print(f"Failed to listen on the debug port {DEBUG_PORT}: {e}")
    else:
        print("Waiting for debugger attach")
        debugpy.wait_for_client()
        print("Debugger attached")

...

In VS Code

  • Make a debugging setting
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Remote Attach",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "${workspaceFolder}"
                }
            ]
        }
    ]
}
  • Set up break points
  • Debug your python code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment