# check the python path for blender
blender --background --python-expr "import sys; print(sys.executable)"
# install debugpy
blender-4.2.1-linux-x64/4.2/python/bin/python3.11 -m pip install debugpy
Wait for a remote debugging client
import debugpy
debugpy.listen(5678)
print("Waiting for debugger attach")
debugpy.wait_for_client()
print("Debugger attached")
...
- run the script with
bin/blender --background --python ...
in the same way as before
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")
...
- run with
DEBUG=1 bin/blender --background --python ...
- 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