Environment
- OS: Windows 11 Enterprise
- VS Code: 1.104.x
- debugpy: latest (1.8.x)
- Python: 3.11
- Repo layout: monorepo with
src/ layout; each sub-package at packages/<name>/src/<name>/
- Shell: PowerShell
Problem
In a monorepo with a src/ layout, running python -m packages.api.main from the workspace root works in a terminal (with PYTHONPATH=packages/api/src). But when launching the same target via VS Code's debugger ("module": "packages.api.main" in launch.json), debugpy prepends its own path manipulation that:
- Overrides
PYTHONPATH in the subprocess environment.
- Sets
cwd to the workspace root unless explicitly overridden.
- Does NOT pick up per-folder
python.defaultInterpreterPath or env activation from a subfolder .vscode/settings.json.
Result: imports that resolve in a terminal fail in the debugger with ModuleNotFoundError, because debugpy's path injection shadows the manually set PYTHONPATH.
Steps to Reproduce
- Monorepo:
C:\D\workspace\packages\api\src\api\__init__.py
launch.json:
{
"type": "python",
"module": "api.main",
"cwd": "${workspaceFolder}/packages/api",
"env": { "PYTHONPATH": "${workspaceFolder}/packages/api/src" }
}
- Terminal run:
cd packages/api && python -m api.main — works.
- F5 debug:
ModuleNotFoundError: No module named 'api'.
Expected
- debugpy should merge the user-specified
env.PYTHONPATH with (not replace) its own injected paths.
- Or: document precisely which env vars debugpy overwrites so
launch.json authors can compensate.
Related
Environment
src/layout; each sub-package atpackages/<name>/src/<name>/Problem
In a monorepo with a
src/layout, runningpython -m packages.api.mainfrom the workspace root works in a terminal (withPYTHONPATH=packages/api/src). But when launching the same target via VS Code's debugger ("module": "packages.api.main"inlaunch.json), debugpy prepends its own path manipulation that:PYTHONPATHin the subprocess environment.cwdto the workspace root unless explicitly overridden.python.defaultInterpreterPathor env activation from a subfolder.vscode/settings.json.Result: imports that resolve in a terminal fail in the debugger with
ModuleNotFoundError, because debugpy's path injection shadows the manually setPYTHONPATH.Steps to Reproduce
C:\D\workspace\packages\api\src\api\__init__.pylaunch.json:{ "type": "python", "module": "api.main", "cwd": "${workspaceFolder}/packages/api", "env": { "PYTHONPATH": "${workspaceFolder}/packages/api/src" } }cd packages/api && python -m api.main— works.ModuleNotFoundError: No module named 'api'.Expected
env.PYTHONPATHwith (not replace) its own injected paths.launch.jsonauthors can compensate.Related
python -m ...fails module resolution only when parent is launched via debugpy #2002 (nested subprocess module resolution) — same root cause, different trigger path