Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
edwardpeek-crown-public opened this issue Apr 4, 2024 · 1 comment
Labels
bug Something isn't working needs repro Issue has not been reproduced yet

Comments

@edwardpeek-crown-public
Copy link

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

  • Dialog box with "Server disconnected unexpectedly" displayed
  • "No module named cowsay" printed in debug console

Expected outcome

  • Subprocess runs without error

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.

@paulacamargo25 paulacamargo25 added the bug Something isn't working label May 30, 2024
@karthiknadig karthiknadig removed their assignment Sep 18, 2024
@karthiknadig
Copy link
Member

Internal Console vs Integrated Terminal is handled in the debug server, so moving this to debugpy.

I also noticed that you are using "python" instead of sys.executable. If I remember correctly that results in a shell execution, so it might not run with the same environment variables.

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

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python-debugger Sep 18, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 18, 2024
@judej judej assigned debonte and unassigned bschnurr and debonte Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

5 participants