microsoft / vscode-python-debugger

Python debugger (debugpy) extension for VS Code.
https://marketplace.visualstudio.com/items?itemName=ms-python.debugpy
MIT License
41 stars 17 forks source link

Parent process venv is not passed through to python subprocesses when using internalConsole #298

Open edwardpeek-crown opened 3 months ago

edwardpeek-crown commented 3 months ago

Configuring "console": "internalConsole" for a launch target causes Python subprocesses spawned by the main debug process to not have their venv inherited correctly.

Repro. steps:

  1. Create a venv and install cowsay
  2. Open VS Code in the venv parent dir
  3. Create files as follows:

test.py:

import subprocess
stdout = subprocess.check_output(["python", "-m", "cowsay", "-t", "test"])
print(stdout.decode())

.vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: test.py",
            "type": "debugpy",
            "request": "launch",
            "program": "test.py",
            "console": "internalConsole", // Doesn't work
//            "console": "integratedTerminal", // Works
        }
    ]
}
  1. Launch the debug target

Actual outcome

Expected outcome

Notes

The underlying cause seems to be that the PATH and VIRTUAL_ENV env vars are not inherited correctly in spawned subprocesses when they are intercepted for debugging.