2.3 KiB
2.3 KiB
Debug Launch Configurations in VS Code
This reference focuses on Python debugging through debugpy using .vscode/launch.json.
Core Structure
A minimal launch file:
{
"version": "0.2.0",
"configurations": []
}
Useful fields for Python configs:
type: Usedebugpy.request: Usuallylaunch, sometimesattach.name: Friendly profile name shown in the Run and Debug panel.program: Script path for script-based entry.module: Module name forpython -m ...style launches.args: CLI arguments.cwd: Working directory.env/envFile: Environment variables.console:integratedTerminalis usually most practical.justMyCode:trueby default; setfalsewhen stepping into dependencies.
Launch vs Attach
Use launch when VS Code should start the process.
Use attach when the process already runs with debugpy listening.
Attach profile example:
{
"name": "Python: Attach (debugpy :5678)",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "127.0.0.1",
"port": 5678
},
"justMyCode": true
}
Remote process side command example:
python -m debugpy --listen 5678 -m your_package.main
Script and Module Patterns
Script pattern:
{
"name": "Python: Script",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/src/app.py",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"justMyCode": true
}
Module pattern:
{
"name": "Python: Module",
"type": "debugpy",
"request": "launch",
"module": "your_package.main",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"justMyCode": true
}
Prefer module mode when imports depend on package layout.
Environment and Interpreter Notes
- Use
envFilefor shared local variables, commonly${workspaceFolder}/.env. - Keep secrets out of committed launch configs.
- Ensure the selected VS Code interpreter matches project tooling.
Troubleshooting
If breakpoints do not hit:
- Confirm the right profile is selected.
- Confirm the file path/module path is correct.
- Disable
justMyCodetemporarily to inspect call flow. - Confirm no stale background process is occupying the expected port.
- Confirm workspace root and
cwdalign with imports.