Skip to content

No support for per-subpackage launch.json + in monorepo: debugger breaks imports that terminal run resolves #2047

Description

@chirag127

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:

  1. Overrides PYTHONPATH in the subprocess environment.
  2. Sets cwd to the workspace root unless explicitly overridden.
  3. 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

  1. Monorepo: C:\D\workspace\packages\api\src\api\__init__.py
  2. launch.json:
    {
      "type": "python",
      "module": "api.main",
      "cwd": "${workspaceFolder}/packages/api",
      "env": { "PYTHONPATH": "${workspaceFolder}/packages/api/src" }
    }
  3. Terminal run: cd packages/api && python -m api.main — works.
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions