No support for per-subpackage launch.json + in monorepo: debugger breaks imports that terminal run resolves #2047
Copy link
Copy link
Open
Description
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 atpackages/<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
PYTHONPATHin the subprocess environment. - Sets
cwdto the workspace root unless explicitly overridden. - Does NOT pick up per-folder
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 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.PYTHONPATHwith (not replace) its own injected paths. - Or: document precisely which env vars debugpy overwrites so
launch.jsonauthors can compensate.
Related
- Nested subprocess
python -m ...fails module resolution only when parent is launched via debugpy #2002 (nested subprocess module resolution) — same root cause, different trigger path
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
rchiodo commentedon Jul 1, 2026
I believe the expected way to handle this is to create a launch.json in the subfolder.
Then you'd just debug the packages/api/src/main file directly from the launch.json at packages/api/.vscode/launch.json
rchiodo commentedon Jul 1, 2026
That works for me if you add the subfolder as a top level folder in the workspace.
Here's what it looks like with the two launch.json files:
Otherwise you could instead set your
env.PYTHONPATHto whatever debugpy has set by printing it at the start of test file.