Skip to content

Pylance stopped using the workspace .venv as defined in user settings.json and use some random other folder .venv #25571

Closed

Description

Environment data

  • Pylance version: 2025.9.1
  • OS and version: macOS tahoe 16.0.1
  • Python version (& distribution if applicable, e.g. Anaconda): uv installed python .venv in this case 3.13 uv 0.8.23 (00d3aa378 2025-10-04)

Code Snippet

Set this in the settings.json

{
  "python.venvPath": "${workspaceFolder}/.venv"
}

I am not even sure this is really useful, but I have already had this from the past and it always worked this way

Then try to import a dependency in your project

import pydantic

And pydantic is flagged as not installed because

Repro Steps

Not sure how to actively reproduce this... If I knew it would probably already be solved

  1. use uv to work with multiple python project with each project dependencies installed in .venv
  2. at some point pylance might break and start using a random folder instead of the workspace folder

Expected behavior

Pylance should use the currently opened workspace folder base .venv, and not any random folder in my laptop

I have set this in my use settings.json to explicitly make sure python LSPs knows that I just want to use local .venv in the workspace folder (quite basic)

{
  "python.venvPath": "${workspaceFolder}/.venv"
}

It has been working for years

Actual behavior

I have asked to github copilot why pylance was not properly resolving dependencies, and it used the pylancePythonEnvironments MCP tool to find that pylance was just casually using the .venv of a completely different folder. Which I never set anywhere (I have been using this other project recently but that's all, like I usually do since I work on multiple projects)

Python environments for 'file:///Users/vemonet/dev/eosc/data-commons-mcp'

### Current python environment ###
'/Users/vemonet/dev/sib/ELIXIR-TrP-KG-training-metadata/.venv/bin/python'

### Python environments available ###
/usr/bin/python3
/opt/homebrew/bin/python3
/opt/homebrew/anaconda3/bin/python
/Users/vemonet/dev/eosc/data-commons-mcp/.venv/bin/python

Logs

Any idea why pylance all of a sudden behaves like this? It happened in the past that pylance struggles to find locally installed dependencies, but usually this is fixed by restarting VSCode or reinstalling the dependencies. In this case doing the 2 many times have not yet solved the problem.

Resolving dependencies using the workspace project .venv seems like the basic default behavior, it's hard to understand how all of sudden pylance decides to use random folders that are not even opened in the current workspace

Thanks a lot!

Activity

  1. github-actions commented on Nov 10, 2025

    @github-actions

    Hi Vincent Emonet (@vemonet), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.


    Explanation:

    • Pylance resolves imports based on the selected Python interpreter, not just the python.venvPath discovery setting.
    • Setting "python.venvPath" only tells Pylance where to look for environments; it does not automatically pick that venv for analysis if another interpreter was previously selected.

    Potential Duplicate Issues – These issues may be duplicates of your report, but may differ in some of the details.


    Potential Workarounds:

    • Select the correct interpreter: Open the Command Palette (⌘+Shift+P), run Python: Select Interpreter, and choose ${workspaceFolder}/.venv/bin/python.
    • Lock the interpreter in settings: Add to .vscode/settings.json:
      {
        "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
      }

    The team will respond to your issue shortly. Please note this is a trial feature and may not be fully accurate. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or was incorrect, please give it a 👎. Your feedback helps us improve!

  2. vemonet commented on Nov 10, 2025

    @vemonet
    Author

    I have added "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python", to the user settings.json but still exact same issue

    That is really problematic, because it completely prevents me to use VSCode for python projects, which is needed for my work, and I will need to cancel my github copilot subscription to move to zed if this persists

    I am not going to manually change the interpreter, because I constantly switch projects and I really need my IDE to be able to pick up the current workspace without manual intervention everytime

  3. rchiodo commented on Nov 10, 2025

    @rchiodo

    This is not a setting that Pylance controls. It's controlled by the Python extension. It determines what interpreter is set. Transferring.

  4. rchiodo commented on Nov 10, 2025

    @rchiodo

    I believe the Python extension defaults to using whatever venv is currently active when VS code starts up. That might be what you're seeing.

  5. vemonet commented on Nov 12, 2025

    @vemonet
    Author

    I have found out a command in the command palette Python: Clear Workspace Interpreter Setting that seems to have fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage-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