Skip to content

Bug: environment being used differs from the one being displayed #836

Description

When using multiple enviroments that are in the same project, maybe as sub-modules or similar, the environment being actually used by vscode is not the one being displayed in the bottom right selector and the environment selected for the whole project ends up being used.
I hope this video can help explain myself

Image
2025-09-13.11-31-55.mp4

As you can see, i have 2 different venvs, one with httpx and one with semver (no particular reason for such choices, i just use them regularly) and, when switching from the main of one module to the other, the venv appears to be changed but in reality it is not (or, at least, vscode does not realize that it changed) and defaults to the project-wide env.

Activity

  1. renan-r-santos commented on Sep 13, 2025

    @renan-r-santos
    Contributor

    This looks similar to microsoft/pylance-release#7443. Even though that issue uses nested projects, these two issues might share the same root cause. It has been almost 2 months without any response from the Pylance team over there :(

  2. FIGIO55 commented on Sep 13, 2025

    @FIGIO55
    Author

    They look similar indeed, I see. That issue shows only nested projects while mine shows same level projects, yes, but because of Python Environments treating the project's root folder as a python project (which is being discussed in #634), this also ends up in the nested projects situation. You can see that in the right tab where 3 python projects are listed (code_pyenv, sub_module_1 and sub_module_2), but only 2 real python projects are present (as shown by the 2 pyproject.toml files)

    After all, the problem seems to lie in the fact that the enviroments of the subprojects are not being used because the environment selected for the root project (which in my case is not a pyhton project but gets treated as such) is taking over.
    To confirm this statement i just tried adding 2 different root folders to my workspace (which ended up creating 2 Python environments root projects) and, when jumping from one root project to the other, the interpreter does actually change. It changes to the specific root project's environment and not the sub-project one, but it does change.

    Image
    2025-09-13.14-28-30.mp4
  3. eleanorjboyd commented on Sep 16, 2025

    @eleanorjboyd
    Member

    Hi! Thanks for the issue and sorry Renan Santos (@renan-r-santos) you haven't gotten a response. Let me see if I can get some movement on that issue as others are hitting it

  4. eleanorjboyd commented on Oct 7, 2025

    @eleanorjboyd
    Member

    think I have found a bug here that may help with the API- will let you know what progress I make

  5. peterchenadded commented on Oct 15, 2025

    @peterchenadded

    This looks similar to an issue I am having.

    My setup

    • venv
    • python-project
    • non-python-project

    I have a code workspace file with python-project and non-python-project as folders.

    With the python environments plugin activate, pylance defaults to using the systems python and not venv. It also updated my user settings.json and set the default python path to system python and would get written even if I remove it.

    If I disabled the python environment plugin, pylance worked without issues and references from venv were detected.

  6. github-actions commented on Oct 30, 2025

    @github-actions

    Hey Eleanor Boyd (@eleanorjboyd), this issue might need further attention.

    Davide Figini (@FIGIO55), you can help us out by closing this issue if the problem no longer exists, or adding more information.

  7. eleanorjboyd commented on Oct 30, 2025

    @eleanorjboyd
    Member

    Hi peterchenadded to clarify pylance is selecting your system python even when you set your workspace python to equal the venv and this is only happening with the python envs ext enabled? You aren't trying to use multiple pythons for a single workspace but instead just want it to use the correct python you selected in your entire workspace right? This might be a different problem which is why I wanted to clarify

  8. peterchenadded commented on Oct 31, 2025

    @peterchenadded

    Hi peterchenadded to clarify pylance is selecting your system python even when you set your workspace python to equal the venv and this is only happening with the python envs ext enabled?

    Yes, I couldn't affect pylance not choosing system python. I was getting import errors coming up.

    Disabling the extension fixed the issue.

    You aren't trying to use multiple pythons for a single workspace but instead just want it to use the correct python you selected in your entire workspace right?

    Yes, I wanted to use a single venv for all folders in the workspace.

    This might be a different problem which is why I wanted to clarify

    Sure no worries.

    Will send through a simplified reproducer if it helps.

  9. eleanorjboyd commented on Nov 5, 2025

    @eleanorjboyd
    Member

    Hello! I wanted to follow up with a summary here. Currently, Pylance does not support multiple environments for a single workspace as supported by the Python Environments Extension. I have now updated the python debugger pre-release so it should work (give the pre-release version of the debugger a try and let me know if not).

    Generally, all Python related things should use the environments as shown in the display bar in the corner (and controlled by the python environments extension) except for Pylance at this moment. If you notice anything else not aligning, please let me know and I will investigate a fix

  10. github-actions commented on Nov 20, 2025

    @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!

  11. eleanorjboyd commented on Jan 13, 2026

    @eleanorjboyd
    Member

    going to close this against microsoft/pylance-release#7443 as that is the issue required and we can follow along there

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

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugtriage-needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions