Skip to content

Virtual environment from an unrelated directory gets selected #21825

Description

Filed on behalf of Guido van Rossum (@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 (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

User Settings


languageServer: "Pylance"

Activity

  1. karrtikr commented on Aug 17, 2023

    @karrtikr

    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.

  2. gvanrossum commented on Aug 17, 2023

    @gvanrossum
  3. karrtikr commented on Aug 17, 2023

    @karrtikr

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

    image

  4. gvanrossum commented on Aug 18, 2023

    @gvanrossum
  5. gvanrossum commented on Aug 19, 2023

    @gvanrossum

    Try these.
    image_6487327(1)
    image_6487327

  6. karrtikr commented on Aug 27, 2023

    @karrtikr

    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.
  7. karrtikr commented on Aug 27, 2023

    @karrtikr

    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.

  8. github-actions commented on Sep 26, 2023

    @github-actions

    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!

  9. locked as resolved and limited conversation to collaborators on Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

info-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions