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

Fail to use an environment variable in python.defaultInterpreterPath on Windows #10692

Closed
wdscxsj opened this issue Mar 21, 2020 · 8 comments
Closed
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release verified Verification succeeded
Milestone

Comments

@wdscxsj
Copy link

wdscxsj commented Mar 21, 2020

Environment data

  • VS Code version: 1.43.1
  • Extension version (available under the Extensions sidebar): 2020.3.69010
  • OS and version: Windows 10 64-bit
  • Python version: 3.8.2

Expected behaviour

An environment variable in python.pythonPath is respected across all platforms.

Actual behaviour

Works on Linux (via Remote SSH), but fails on Windows.

Steps to reproduce:

  1. Specify "python.pythonPath": "{env:PYTHON_FOR_VSCODE}" in settings.json.
  2. Set a Windows environment variable PYTHON_FOR_VSCODE to point to an installed Python interpreter, in my case C:\Tools\Python3\python.exe.
  3. Restart VSCode, and open a hello.py.
  4. The yellow prompt "Select Python Interpreter" persists.
    • When it's clicked, a combobox comes to say current: {env:PYTHON_FOR_VSCODE}, and lists my locally installed Python interpreters, including C:\Tools\Python3\python.exe. Choosing it works fine, but defeats the purpose of using an environment variable.
    • In VSCode's Terminal, %PYTHON_FOR_VSCODE% --version runs as expected.
@wdscxsj wdscxsj added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Mar 21, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Mar 23, 2020
@karrtikr
Copy link

Hi @wdscxsj 👋
We're deprecating python.pythonPath setting with #10375, moving it out of settings, so we don't plan to support this enhancement.

I am assuming you're using environment variables here as you don't want to commit your pythonPath to source control. We plan to store settings in a VSCode storage instead of settings.json files, so you should no longer face this once #10375 gets in. Closing this in favor of that.

@ghost ghost removed the triage label Mar 24, 2020
@wdscxsj
Copy link
Author

wdscxsj commented Mar 24, 2020

@karrtikr OK... Actually my setting "python.pythonPath": "{env:PYTHON_FOR_VSCODE}" was intended to select the preconfigured "default Python" for each machine my VSCode could connect to. It covers the folder/project mode as well as the single file case. Will #10375 work in both cases?

@karrtikr
Copy link

I see. In that case, consider the workaround:

If no interpreter is specified in settings, we check the PATH environment variable to autoselect the interpreter. You can append the preconfigured "default Python" to PATH environment variable instead of storing it in PYTHON_FOR_VSCODE, and it'll automatically be picked up if don't have python.pythonPath present in settings.

@wdscxsj
Copy link
Author

wdscxsj commented Mar 24, 2020

Sure, that's good enough. Actually it's been a surprise to me that the first Python on PATH is not automatically picked.

@karrtikr
Copy link

I just realized that the original bug you described will still be applicable for #10375 . I am reopening the issue and changing the title accordingly.

@karrtikr karrtikr reopened this Mar 24, 2020
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Mar 24, 2020
@karrtikr karrtikr changed the title Fail to use an environment variable in python.pythonPath on Windows Fail to use an environment variable in python.defaultInterpreterPath on Windows Mar 24, 2020
@karrtikr karrtikr added area-environments Features relating to handling interpreter environments needs PR regression Bug didn't exist in a previous release labels Mar 24, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Mar 24, 2020
@karrtikr karrtikr removed their assignment Mar 24, 2020
@wdscxsj
Copy link
Author

wdscxsj commented Mar 24, 2020

Thanks a lot for your active work!

In sum, please help with a configuration of default (no-confirmation) Python that works across multiple hosts and under both folder mode and single file mode. My original idea of per-host PYTHON_FOR_VSCODE only works in theory.

@karrtikr
Copy link

Python that works across multiple hosts

Can you simply use User settings or Remote settings in this case?

@karrtikr
Copy link

You need to put the $ for "python.pythonPath": "${env:PYTHON_FOR_VSCODE}" to work, I think you missed that. Closing this as it's working as intended.

@karrtikr karrtikr added this to the October 2021 milestone Oct 21, 2021
@karrtikr karrtikr added the verified Verification succeeded label Oct 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2021
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 regression Bug didn't exist in a previous release verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants