Skip to content

python.DefaultInterpreterPath not respected in multi-root workspace. #18207

Closed

Description

@urscion

VS Code version

1.63.2

Extension version

v2021.12.1559732655

OS type

Windows

OS version

19043.1348

Python distribution

python.org

Python version

3.9.1

Language server

Pylance

Expected behaviour

When I set python.defaultInterpreterPath in my workspace configuration file, the Python extension should use that interpreter.

Actual behaviour

The "Choose a Python Interpreter" selection is shown and no interpreter has been selected.

image

Steps to reproduce

code-workspace settings file

{
    "settings": {
        "python.defaultInterpreterPath": "${workspaceFolder}/.virtualenvs/mtg_39_64/Scripts/python.exe",
    }
}

When attempting to clear the workspace interpreter setting (off a fresh restart) and resetting it via the command palette prompts, it does not work either.
image
image

Logs

And these are the results of my Python output. It appears to be not respecting the pre-defined ${workspaceFolder} variable. However, I've tried an absolute path as well, as well as my system-level Python paths and they do not work either (but no scandir errors are displayed).

Results

Experiment 'pythonaa' is active
Experiment 'pythonTensorboardExperiment' is active
Experiment 'pythonSurveyNotificationcf' is active
Experiment 'PythonPyTorchProfiler' is active
Experiment 'pythonDeprecatePythonPath' is active
> conda info --json
> "C:\Program Files\Python39\python.exe" ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
> "C:\Program Files\Python38\python.exe" ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
> ~\.virtualenvs\django-tutorial_39_64\Scripts\python.exe ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
> ~\.virtualenvs\ugit_39_64\Scripts\python.exe ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
Starting Pylance language server.
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
[ERROR 2021-11-19 16:25:49.126]: Diagnostic Code: InvalidPythonInterpreterDiagnostic, Message: No Python interpreter is selected. You need to select a Python interpreter to enable features such as IntelliSense, linting, and debugging.
Diagnostic Code: InvalidPythonInterpreterDiagnostic, Message: No Python interpreter is selected. You need to select a Python interpreter to enable features such as IntelliSense, linting, and debugging.
> conda --version
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
[ERROR 2021-11-19 16:27:12.152]: Python Extension: sendTelemetry [Error: ENOENT: no such file or directory, scandir 'C:\Users\Peter\AppData\Local\Programs\Microsoft VS Code\${workspaceFolder}\.virtualenvs\mtg_39_64\Scripts'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'scandir',
  path: 'C:\\Users\\Peter\\AppData\\Local\\Programs\\Microsoft VS Code\\${workspaceFolder}\\.virtualenvs\\mtg_39_64\\Scripts'
}

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    bugIssue identified by VS Code Team member as probable bug
    triage-neededNeeds assignment to the proper sub-team
    on Dec 19, 2021
  2. added
    area-environmentsFeatures relating to handling interpreter environments
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Dec 21, 2021
  3. kimadeline commented on Dec 21, 2021

    @kimadeline

    Hi Peter (@urscion), thank you for reaching out.

    There are 2 things here:

    It appears to be not respecting the pre-defined ${workspaceFolder} variable.

    There's a bug where we don't resolve ${workspaceFolder} when it's in the python.defaultInterpreterPath setting, thank you for reporting it 🙂

    However, I've tried an absolute path as well, as well as my system-level Python paths and they do not work either

    I could not replicate your issue here, when I set a valid interpreter path in my python.defaultInterpreterPath setting in my workspace file it gets detected correctly:

    image

    Does interpreter selection work correctly for you in non-multiroot workspaces?

  4. brettcannon commented on Feb 4, 2022

    @brettcannon
    Member

    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.

  5. OmeGak commented on Feb 14, 2022

    @OmeGak

    I'm also experiencing this problem. Would it be possible to re-open this issue Brett Cannon (@brettcannon)?

    The python.DefaultInterpreterPath defined in the global and workspace settings are completely ignored in multi-root workspaces. It only works unless it's defined in the .vscode/settings.json files.

    Kim-Adeline Miguel (@kimadeline) wrote:

    Does interpreter selection work correctly for you in non-multiroot workspaces?

    Interpreter selection seems to work fine in non-multiroot workspaces. It works inconsistently in multi-root workspaces. Sometimes selecting interpreter from the dialog does nothing. When it works, it's not clear where this information is stored as it's not saved in the workspace.json nor .vscode/settings.json files. Reloading window preserves the selected interpreter sometimes only.

    Kim-Adeline Miguel (@kimadeline) wrote:

    There's a bug where we don't resolve ${workspaceFolder} when it's in the python.defaultInterpreterPath setting, thank you for reporting it 🙂

    Is there an issue already for this? It would be nice to be able to define python.defaultInterpreterPath like this in multi-root workspaces:

    - "python.defaultInterpreterPath": "/Users/ome/Code/orgs/indico/indico-un/.venv/bin/python",
    + "python.defaultInterpreterPath": "${workspaceFolder:indico-un}/.venv/bin/python",
  6. kimadeline commented on Feb 22, 2022

    @kimadeline

    Hi Alejandro Avilés (@OmeGak),

    The python.DefaultInterpreterPath defined in the global and workspace settings are completely ignored in multi-root workspaces. It only works unless it's defined in the .vscode/settings.json files.

    Please provide repro steps, and ideally, a test repo I could use to try and replicate the issue on my end.

    Is there an issue already for this? It would be nice to be able to define python.defaultInterpreterPath like this in multi-root workspaces:

    Support for ${workspaceFolder} was added in #18351. Does VS Code support ${workspaceFolder:indico-un} system variables?

  7. OmeGak commented on Feb 24, 2022

    @OmeGak

    Hi Kim-Adeline Miguel (@kimadeline). Let me know if you can reproduce with these steps.

    1. Clone test repo.
    2. Open workspace.code-workspace on VSCode.
    3. Create a virtualenv on the workspace root directory (e.g. PIPENV_VENV_IN_PROJECT=1 pipenv install).
    4. Open python-a/foo.py or python-b/bar.py.
    5. Notice that python.defaultInterpreterPath defined in workspace.code-workspace is ignored and VSCode reports an error:

    No Python interpreter is selected. You need to select a Python interpreter to enable features such as IntelliSense, linting, and debugging.

    Additionally:

    1. Try selecting interpreter from the python.defaultInterpreterPath setting on the interpreter selection dialog does nothing.
    2. Notice that it does nothing.

    Support for ${workspaceFolder} was added in #18351. Does VS Code support ${workspaceFolder:indico-un} system variables?

    The feature exists (https://code.visualstudio.com/docs/editor/variables-reference#_variables-scoped-per-workspace-folder) but it's not clear to me if it's available everywhere.

  8. kimadeline commented on Mar 1, 2022

    @kimadeline

    Thank you for providing a test repo and steps!

    ${workspaceFolder} will change depending on which folder you're in. So, if you're in python-a/foo.py, ${workspaceFolder}/.venv/bin/python will resolve to path/to/tmp-python-multiroot/python-a/.venv/bin/python, which doesn't exist after following the steps above. You can see the extension trying to resolve this path in the Python output panel:

    image

    The only Python environment available is in tmp-python-multiroot, not in any of the subfolders. Since tmp-python-multiroot is not a workspace folder, this environment is not picked up by the extension.

    If you want ${workspaceFolder}/.venv/bin/python to work, you need to create a .venv virtual environment under every single one of your workspace folders.

    As for multiroot-workspace variable scoping, the extension does not support that at the moment. Feel free to open a feature request (and upvote it) to gauge community interest!

  9. OmeGak commented on Mar 3, 2022

    @OmeGak

    Thanks for your response Kim-Adeline Miguel (@kimadeline)!

    ${workspaceFolder} will change depending on which folder you're in.

    It was my impression that ${workspaceFolder} pointed to the directory where the workspace file is located in multi-root workspaces. Knowing now that it points to the actual project folder, I made it work on the test repo by setting:

    "python.defaultInterpreterPath": "${workspaceFolder}/../.venv/bin/python"

    python.defaultInterpreterPath is then correctly respected and I consider this issue solved. Feel free to close it. 🎯


    As for multiroot-workspace variable scoping, the extension does not support that at the moment. Feel free to open a feature request (and upvote it) to gauge community interest!

    This would nicely solve my real use case, which looks more like this:

    /
    ├── python-a/
    │  ├── .venv/
    │  └── foo.py
    ├── python-b/
    │  └── bar.py
    

    To make it work with defaultInterpreterPath I need to configure it like this:

    "python.defaultInterpreterPath": "${workspaceFolder}/../python-a/.venv/bin/python"

    If multiroot-workspace variable scoping were available I could do the following instead:

    "python.defaultInterpreterPath": "${workspaceFolder:python-a}/.venv/bin/python"

    Should I propose this in https://github.com/microsoft/vscode-python or https://github.com/microsoft/vscode?

  10. kimadeline commented on Mar 3, 2022

    @kimadeline

    Glad to hear it woks now! And feel free to open this feature request on this repo (https://github.com/microsoft/vscode-python), and link to your comment above 🙂

    Thank you!

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

Metadata

Metadata

Labels

area-environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions