You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Virtual environment from an unrelated directory gets selected #21825
When I open a repo directory (I use the command line: code ~/<dirname>/), a seemingly random venv gets activated. What I want is: either a venv with a standard name (e.g. 'venv' or '.venv') in that repo (whether or not it's managed by git) is activated, or possibly a venv with a standard name from my home directory (e.g. ~/venv or ~/.venv). But what I get is a venv in some other repo that I might have last opened days or weeks ago gets activated. And sometimes no venv gets activated. I don't know how to control what happens, which is probably the most frustrating part.
Steps to reproduce:
Open VS Code on a repo, say ~/cpython.
In the shell, type 'code ~/peps/'.
In the new VS Code window that appears, create a shell window.
Observe that in that shell window, another repo's venv is opened, say ~/devguide/venv/.
Diagnostic data
Python version (& distribution if applicable, e.g. Anaconda): 3.8.5
Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
Value of the python.languageServer setting: Pylance
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
2023-08-15 15:29:54.747 [info] Experiment 'pythonPromptNewFormatterExt' is active
2023-08-15 15:29:54.747 [info] Experiment 'pythonPromptNewToolsExt' is active
2023-08-15 15:29:54.747 [error] Dir "/Users/guido/peps" is not watchable (too many files)
2023-08-15 15:29:54.747 [info] Test server listening.
2023-08-15 15:29:54.747 [info] Python interpreter path: ~/devguide/venv/bin/python
2023-08-15 15:29:56.776 [info] Starting Pylance language server.
2023-08-15 15:30:06.160 [info] Send text to terminal: source /Users/guido/devguide/venv/bin/activate
Here are screenshots of the top and bottom of that menu.
FWIW today the outcome is different— it chooses ~/.venv, which is more reasonable.
python.org/~guido
What I want is: either a venv with a standard name (e.g. 'venv' or '.venv') in that repo
I can confirm that "⭐" appears next to the interpreter which is expected to be selected (./venv/bin/python), so at least our guess is right. But our recommended interpreter was overridden by one of two things:
"python.defaultInterpreterPath": Did you set this setting? If not, please remove it from "User settings" or settings.json in your repository.
Previously configured interpreter using the menu. This can be cleared using Python: Clear cache and reload window command for all repos, or Python: Clear Workspace setting command for current repo.
My guess is, "python.defaultInterpreterPath" was previously inadvertently set in User settings, this can happen when working on an isolated Python file without opening a repo/project in VS Code.
We can look into improving this experience if that's the case.
Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.
Activity
karrtikr commentedon Aug 17, 2023
Can I please get a screenshot of the interpreter list right after step 2 when
~/pepswas opened? UsePython: Select Interpretercommand:Btw here's how we automatically choose environments: official documentation. If a local venv is present, we ideally should be choosing that.
gvanrossum commentedon Aug 17, 2023
karrtikr commentedon Aug 17, 2023
Sorry but I don't see any screenshots 😅 maybe because the comment was sent through an email?
gvanrossum commentedon Aug 18, 2023
gvanrossum commentedon Aug 19, 2023
Try these.


Do not filter using scheme when filtering environments (#21862)
karrtikr commentedon Aug 27, 2023
I can confirm that "⭐" appears next to the interpreter which is expected to be selected (
./venv/bin/python), so at least our guess is right. But our recommended interpreter was overridden by one of two things:"python.defaultInterpreterPath": Did you set this setting? If not, please remove it from "User settings" orsettings.jsonin your repository.Python: Clear cache and reload windowcommand for all repos, orPython: Clear Workspace settingcommand for current repo.karrtikr commentedon Aug 27, 2023
My guess is,
"python.defaultInterpreterPath"was previously inadvertently set in User settings, this can happen when working on an isolated Python file without opening a repo/project in VS Code.We can look into improving this experience if that's the case.
Do not filter using scheme when filtering environments (microsoft#21862)
github-actions commentedon Sep 26, 2023
Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.
Happy Coding!