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

[Windows] extension overwrites PATH, preventing virtual environment usage #609

Closed
mcrumiller opened this issue Feb 11, 2025 · 3 comments
Closed
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@mcrumiller
Copy link

mcrumiller commented Feb 11, 2025

Since the no-config debugging update, my local venv python instances are not accessible via the terminal unless I explicitly activate the environment. I open a new terminal, and it appears my environment is activated, but it's not:

Microsoft Windows [Version 10.0.22631.4751]
(c) Microsoft Corporation. All rights reserved.

(.venv) C:\Projects>

However, my virtual environment is not available:

(.venv) C:\Projects>where python
C:\Users\me\AppData\Local\Programs\Python\Python312\python.exe
C:\Users\me\AppData\Local\Programs\Python\Python313\python.exe

If I manually activate, I then see the local instance on the path:

(.venv) C:\Projects>.venv\Scripts\activate.bat
(.venv) C:\Projects>where python
C:\Projects\.venv\Scripts\python.exe
C:\Users\me\AppData\Local\Programs\Python\Python312\python.exe
C:\Users\me\AppData\Local\Programs\Python\Python313\python.exe

This is also visible with an ECHO %PATH% from the console.

When I run Terminal: Show Environment Contributions, I see the following:

# Terminal Environment Changes

## Extension: ms-python.python


## Extension: ms-python.debugpy

Enables use of [no-config debugging](https://github.com/microsoft/vscode-python-debugger/wiki/No%E2%80%90Config-Debugging), `debugpy <script.py>`, in the terminal.

Enables use of [no-config debugging](https://github.com/microsoft/vscode-python-debugger/wiki/No%E2%80%90Config-Debugging), `debugpy <script.py>`, in the terminal. (workspace)

- `PYDEVD_DISABLE_FILE_VALIDATION=1`
- `DEBUGPY_ADAPTER_ENDPOINTS=C:\Users\<me>\AppData\Local\Temp\noConfigDebugAdapterEndpoints-34367d754ac0c5bc02ac\debuggerAdapterEndpoint.txt`
- `PATH=${env:PATH};c:\Users\me\.vscode\extensions\ms-python.debugpy-2025.0.0-win32-x64\bundled\scripts\noConfigScripts`
- `BUNDLED_DEBUGPY_PATH=c:\Users\me\.vscode\extensions\ms-python.debugpy-2025.0.0-win32-x64\bundled\libs\debugpy`

The PATH command above is probably overwriting the path and removing the local environment path.

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 11, 2025
@mcrumiller mcrumiller changed the title [Windows] debugpy overwrites PATH, preventing virtual environment usage [Windows] extension overwrites PATH, preventing virtual environment usage Feb 11, 2025
@karthiknadig
Copy link
Member

@mcrumiller You might be running into this issue microsoft/vscode-python#24810

@mcrumiller
Copy link
Author

Thanks @karthiknadig, this did indeed resolve the issue after reloading VS Code.

All of my coworkers have encountered this problem as well, and it's a bit nefarious because it looks like the virtual environment is activated (the console shows the (venv name) prepended), but the path to the venv has been removed from the PATH. I see that the other issue was closed as not planned, but this seems like a valid issue--is there a fix in the works? Thank you!

@karthiknadig
Copy link
Member

@mcrumiller We are getting rid of that experiment because of the problems like the ones you faced.

The thing that we wanted to achieve was avoid sending a command to the terminal to activate. The reason is potential collision with user typing in the terminal, other extensions attempting to send things to terminal, debugger not getting the right terminal because debugger command ran before the terminal activation etc. This experiment was supposed to address that.

Unfortunately, the solution was not ideal. We attempt to run the activation script in a "sandbox" like mode and extract the environment changes. These changes however are acquired for the default terminal shell. This is where the problem starts. We now have to merge these changes with all the other shell environment variables. It does not do it right, sometimes it is not possible to do it right. It can also sometimes cause a problem where terminals get stuck in "reactivating" mode.

We are working on a different approach. This is the tracking issue for fixing the problem: microsoft/vscode-python#24699

@karthiknadig karthiknadig closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants