Title: Nested subprocess `python -m ...` fails module resolution only when parent is launched via debugpy · Issue #2002 · microsoft/debugpy · GitHub
Open Graph Title: Nested subprocess `python -m ...` fails module resolution only when parent is launched via debugpy · Issue #2002 · microsoft/debugpy
X Title: Nested subprocess `python -m ...` fails module resolution only when parent is launched via debugpy · Issue #2002 · microsoft/debugpy
Description: Summary In a Windows project with src/ layout, a parent Python module runs correctly under debugpy, but a child subprocess started from that parent with: python -m my_tools.tasks.validation.main fails with: No module named my_tools.tasks...
Open Graph Description: Summary In a Windows project with src/ layout, a parent Python module runs correctly under debugpy, but a child subprocess started from that parent with: python -m my_tools.tasks.validation.main fa...
X Description: Summary In a Windows project with src/ layout, a parent Python module runs correctly under debugpy, but a child subprocess started from that parent with: python -m my_tools.tasks.validation.main fa...
Opengraph URL: https://github.com/microsoft/debugpy/issues/2002
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Nested subprocess `python -m ...` fails module resolution only when parent is launched via debugpy","articleBody":"## Summary\n\nIn a Windows project with `src/` layout, a parent Python module runs correctly under `debugpy`, but a child subprocess started from that parent with:\n\n```bash\npython -m my_tools.tasks.validation.main\n```\n\nfails with:\n\n```text\nNo module named my_tools.tasks.validation.main\n```\n\nThe exact same child command succeeds outside debugpy (normal terminal/task run).\n\n---\n\n## Environment\n\n- OS: Windows (PowerShell)\n- Python: virtualenv interpreter (`.venv\\Scripts\\python.exe`), debugpy 1.8.19\n- VS Code Python extension (debugpy launcher used by VS Code)\n- Project layout: `src/my_tools/...`\n- `PYTHONPATH` in launch config: `\u003cworkspace>/src`\n\n---\n\n## Expected behavior\n\nIf parent process is launched via debugpy and parent starts child with:\n\n```bash\n\u003cvenv_python> -m my_tools.tasks.validation.main ...\n```\n\nthen child should resolve and execute module exactly as in terminal mode.\n\n---\n\n## Actual behavior\n\nWhen parent is launched via debugpy (`module` launch in `launch.json`), child subprocess fails:\n\n```text\nNo module named my_tools.tasks.validation.main\n```\n\nWhen parent is launched normally (no debugpy), same child command succeeds.\n\n---\n\n## Reproduction pattern\n\n### Parent debug launch (fails in child)\n\nVS Code launch command shape:\n\n```text\n\u003cvenv>\\python.exe \u003c...>\\debugpy\\launcher \u003cport> -- -m my_tools.service.runner.main ...\n```\n\nInside parent:\n\n```python\ncmd = [\n sys.executable,\n \"-m\",\n \"my_tools.tasks.validation.main\",\n \"--help\",\n]\nsubprocess.run(\n cmd,\n cwd=\"\u003cworkspace>\",\n env=env_with_pythonpath,\n capture_output=True,\n text=True,\n)\n```\n\nResult under debug launch:\n\n```text\nstderr: No module named my_tools.tasks.validation.main\n```\n\n### Parent non-debug launch (works)\n\n```bash\npython -m my_tools.service.runner.main ...\n```\n\nResult: child module resolves and completes successfully.\n\n### Manual debugpy CLI launch (also fails)\n\nAfter installing `debugpy` into the same venv, launching parent via CLI debugpy reproduces the same child failure:\n\n```bash\npython -m debugpy --listen 5678 -m my_tools.service.runner.main --queue-root \u003c...> --work-root \u003c...> --once --log-level DEBUG\n```\n\nResult:\n\n```text\nstderr: No module named my_tools.tasks.validation.main\n```\n\n---\n\n## Sanity checks already done\n\nAll of the following succeed in same venv:\n\n```bash\npython -c \"import os,sys,importlib.util as u,my_tools; print(sys.executable); print(os.getenv('PYTHONPATH')); print(u.find_spec('my_tools.tasks.validation.main'))\"\n```\n\n`find_spec(...)` returns valid `ModuleSpec` under `\u003cworkspace>/src/my_tools/...`.\n\nAlso succeeds:\n\n```bash\npython -c \"import os,sys,subprocess; env=os.environ.copy(); env['PYTHONPATH']=r'\u003cworkspace>\\\\src;\u003cworkspace>/src'; cmd=[sys.executable,'-m','my_tools.tasks.validation.main','--help']; r=subprocess.run(cmd,cwd=r'\u003cworkspace>',env=env,capture_output=True,text=True); print(r.returncode); print(r.stderr)\"\n```\n\nReturn code is `0`, stderr empty.\n\n---\n\n## Why this looks debugpy-related\n\n- Same interpreter path.\n- Same module path.\n- Same child command works outside debugpy.\n- Failure appears when parent is launched via debugpy (VS Code launcher and manual `python -m debugpy`).\n- The failing point is nested child module resolution via `-m`.\n\n---\n\n## Current workaround\n\n- Run parent as normal task/terminal (non-debug) for production-like execution.\n- Alternative code workaround: launch child by script path instead of `-m`, e.g.:\n\n```bash\npython \u003cworkspace>/src/my_tools/tasks/validation/main.py ...\n```\n\n---\n\n## Question to maintainers\n\nIs this a known issue/limitation with:\n\n- debugpy launcher + nested subprocess `-m` calls\n- `src/` layout + `PYTHONPATH`\n- Windows-specific env/path propagation\n\nand is there a recommended debugpy setting to make nested child `-m` module resolution deterministic?\n","author":{"url":"https://github.com/michaeltufar","@type":"Person","name":"michaeltufar"},"datePublished":"2026-03-04T14:14:43Z","url":"https://github.com/microsoft/debugpy/issues/2002"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7bb2b6b7-0c64-6444-b268-5dcdb5b5685a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1EC:2EC4C2:B8248:102596:6AFE8D9B |
| html-safe-nonce | fd784219c778da6102588bf6cacd1e8a9a789dac9d33bcbe6f1541daca12b2f2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUVDOjJFQzRDMjpCODI0ODoxMDI1OTY6NkFGRThEOUIiLCJ2aXNpdG9yX2lkIjoiMTkxNjQ0MzIwNzAyNTk4Njk3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f603420bf3dd3a3709b194c2bce3984f93b4463d03fb80b0ae5daa770e2fb64b |
| hovercard-subject-tag | issue:4022231060 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/debugpy/2002/issue_layout |
| twitter:image | https://opengraph.githubassets.com/028f2cdbdf78658436460a7985b8c14a8dde73a60aa706d736f3b24f95af58ae/microsoft/debugpy/issues/2002 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/028f2cdbdf78658436460a7985b8c14a8dde73a60aa706d736f3b24f95af58ae/microsoft/debugpy/issues/2002 |
| og:image:alt | Summary In a Windows project with src/ layout, a parent Python module runs correctly under debugpy, but a child subprocess started from that parent with: python -m my_tools.tasks.validation.main fa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | michaeltufar |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/debugpy git https://github.com/microsoft/debugpy.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 234187391 |
| octolytics-dimension-repository_nwo | microsoft/debugpy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 234187391 |
| octolytics-dimension-repository_network_root_nwo | microsoft/debugpy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width