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

Virtual environment from an unrelated directory gets selected #21825

Closed
brettcannon opened this issue Aug 16, 2023 · 8 comments
Closed

Virtual environment from an unrelated directory gets selected #21825

brettcannon opened this issue Aug 16, 2023 · 8 comments
Assignees
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@brettcannon
Copy link
Member

Filed on behalf of @gvanrossum ...

Behaviour

Expected vs. Actual

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:

  1. Open VS Code on a repo, say ~/cpython.
  2. In the shell, type 'code ~/peps/'.
  3. In the new VS Code window that appears, create a shell window.
  4. 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 (ViewOutput, 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

User Settings


languageServer: "Pylance"

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Aug 16, 2023
@karrtikr
Copy link

Can I please get a screenshot of the interpreter list right after step 2 when ~/peps was opened? Use Python: Select Interpreter command:

image

Btw here's how we automatically choose environments: official documentation. If a local venv is present, we ideally should be choosing that.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Aug 17, 2023
@gvanrossum
Copy link

gvanrossum commented Aug 17, 2023 via email

@karrtikr
Copy link

Sorry but I don't see any screenshots 😅 maybe because the comment was sent through an email?

image

@gvanrossum
Copy link

gvanrossum commented Aug 18, 2023 via email

@gvanrossum
Copy link

Try these.
image_6487327(1)
image_6487327

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Aug 20, 2023
karrtikr pushed a commit that referenced this issue Aug 22, 2023
For #21825

On codespaces, it was leading to workspace environments not being
displayed, which could mess up auto-selection.
@karrtikr
Copy link

karrtikr commented Aug 27, 2023

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.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Aug 27, 2023
@karrtikr
Copy link

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.

anthonykim1 pushed a commit to anthonykim1/vscode-python that referenced this issue Sep 12, 2023
For microsoft#21825

On codespaces, it was leading to workspace environments not being
displayed, which could mess up auto-selection.
@github-actions
Copy link

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!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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

3 participants