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

venv not being recognised when auto activated in terminal upon opening despite positive confirmation message received. #24831

Closed
HansMellman opened this issue Feb 18, 2025 · 4 comments
Assignees
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@HansMellman
Copy link

User for around 2 years - recent issue. I create a venv each time I begin a new project, install my dependencies and begin to work. Recently, when I create a new project, create my venv and open the terminal I get the confirmation message that the venv has been activated (despite it not displaying 'venv' as per the conf message) however, when I try to install my dependencies it puts them in the global installation. Fine, I then tried to manually activate the venv and install the packages (this works) and close the terminal and re-open to again depend on the auto activation venv feature to try and run my code, it's not able to find the dependencies as again, it's just relying on the global installation it seems. Despite it telling me that it has successfully activated the venv.

I have tried every troubleshooting tip I could find from closing and re-opening the terminal session, the entire vscode session, manually pointing to the python.exe in the venv via command palette, making sure the setting for auto activation is checked in the settings, ensuring that the selection menu in the bottom right hand corner is pointing to the correct venv, uninstalling all extensions including Python and reinstalling one by one and retrying.

I am able to manually activate the venv via the conventional method and it does work, so it leads me to believe the issue is not with venv itself but VSCode and the auto activation feature.

If you need any further info please let me know

  • VS Code Version: Version: 1.97.2 (user setup)
    Commit: e54c774e0add60467559eb0d1e229c6452cf8447
    Date: 2025-02-12T23:20:35.343Z
    Electron: 32.2.7
    ElectronBuildId: 10982180
    Chromium: 128.0.6613.186
    Node.js: 20.18.1
    V8: 12.8.374.38-electron.0

  • OS Version: Windows_NT x64 10.0.19045

@karthiknadig
Copy link
Member

@HansMellman This might be a side effect of an experiment. Try adding this to disable it. It has been out for a while, but some times it seems to fail and cause this issue.

    "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]

@karthiknadig karthiknadig transferred this issue from microsoft/vscode Feb 19, 2025
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 19, 2025
@HansMellman
Copy link
Author

Thanks for the prompt response, Karthik. I can confirm that adding this to my settings.json has resolved the issue - the terminal also now clearly shows the venv has been activated unlike before (there is no confirmation message as before but a clear indicator within the terminal window itself).

@dnabb
Copy link

dnabb commented Feb 28, 2025

@karthiknadig I have been having the same issue since the last few days, and I suspect this is essentially the same problem as this issue.

Basically, other extensions that modify the PATH end overriding the contributions that the Python extension does.

More in detail, I think the Python Debugger extension has recently started to make contributions to the PATH, and this is causing the issue for me.

Python Debugger: Enables use of [no-config debugging](vscode-file://vscode-app/c:/Users/DanieleAbbatelli/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html), debugpy <script.py>, in the terminal.

@karthiknadig
Copy link
Member

@dnabb Add this to your User settings, followed by reloading VS Code should resolve. You can also try running Python: Clear cache and reload.

    "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]

Typically extension contributions should not override each other, that issue should be handled in code VS Code. There is no way for each extension to know what modifications were made by other extensions. This really depends on order of loading.

I am closing this issue as the original concern from the issue creator has been addressed.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants