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

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

Closed
1 task done
urscion opened this issue Dec 19, 2021 · 8 comments
Closed
1 task done

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

urscion opened this issue Dec 19, 2021 · 8 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug

Comments

@urscion
Copy link

urscion commented Dec 19, 2021

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
@urscion urscion added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Dec 19, 2021
@karrtikr karrtikr added area-environments Features relating to handling interpreter environments triage and removed triage-needed Needs assignment to the proper sub-team labels Dec 21, 2021
@kimadeline
Copy link

Hi @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?

@brettcannon
Copy link
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.

@OmeGak
Copy link

OmeGak commented Feb 14, 2022

I'm also experiencing this problem. Would it be possible to re-open this issue @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.

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

@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",

@brettcannon brettcannon reopened this Feb 14, 2022
@brettcannon brettcannon removed the info-needed Issue requires more information from poster label Feb 14, 2022
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 14, 2022
@karthiknadig karthiknadig removed the triage-needed Needs assignment to the proper sub-team label Feb 15, 2022
@kimadeline
Copy link

Hi @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?

@kimadeline kimadeline added the info-needed Issue requires more information from poster label Feb 22, 2022
@OmeGak
Copy link

OmeGak commented Feb 24, 2022

Hi @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.

@brettcannon brettcannon removed the info-needed Issue requires more information from poster label Feb 24, 2022
@kimadeline
Copy link

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!

@OmeGak
Copy link

OmeGak commented Mar 3, 2022

Thanks for your response @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?

@kimadeline
Copy link

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!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

6 participants