-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Set as Interpreter hint displayed even when non-default setting is active #736
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
Comments
Unfortunately this feature is not supported. You need to specify the path in the settings.json. |
You misunderstand. As described in the "Actual Behavior", the interpreter is already set in settings.json. |
Got it. |
Basically, it should not offer to set the interpreter if the settings already have a non-default one. |
If you click the code lense, then it'll change the interpret to point to the system bedroom, as that's what's in the shebang.
It should, if users wish to change the value to something that's defined in the shebang, irrespective of the current value in the settings. |
No. It will use the first one that is in the PATH. With a virtualenv active, that will be the one in the virtualenv, not the system one. |
VSCode seems to consider that line from it's own environment, not from the environment in the venv that is being used. |
...and that matters because a venv will change PATH, as explained. |
I'm sorry, but I don't quite understand the issue,
Initially you seem to indicate that the code lens shouldn't appear, now you're saying that the interprerter being used is incorrect. These are two separate issues. Hence the confusion on my part.
import sys
print(sys.executable) |
By inspecting PATH in a venv and (confirming by) seeing which python interpreter is launched. I actually checked the shellscripts that activate a venv in Python 3.5 and they are modifying the PATH to point to the python in the venv. See also for example: https://stackoverflow.com/questions/2429511/why-do-people-write-the-usr-bin-env-python-shebang-on-the-first-line-of-a-pyt Without this behavior such #!/usr/bin/env would indeed not work. But it does. Just not in VSCode, because it's oblivious to the fact that the venv is changing the environment.
I'm not doing anything, I'm trying to write a Python code and I have suggestions/hints popping up in VSCode to change (break!) "python.pythonPath" by pointing it to the wrong thing, thus breaking my application IF I were to try running it.
Terminal
Debug mode in VSCode
|
As far as I can tell, the underlying problem is that VSCode is not activating the venv before checking what the #!/usr/bin/env python3 line actually points to. Without seeing the source, I'm guessing, but it probably never activates them, and just relies on using the "python.pythonPath" executable to run and debug the given Python. This works fine for running python code, but it won't give the correct result for determining what the bang line actually refers to. So in those cases, "Set as Interpreter" hints will just do the wrong thing. |
As I mentioned earlier, the shabang is something that is not supported by VS Code when debugging or the like. |
I understand, but then it shouldn't show a permanent "Set as Interpreter" either. |
And the shebang isn't needed for correctly debugging. As said, I've already set the pythonPath. The problem is that VSCode (permanently!) insists with a hint that it can set the pythonPath, when in reality it cannot, and will break the code if it tries. |
It should, if users wish to change the value to something that's defined in the shebang, irrespective of the current value in the settings. |
But we just established that this does not work. |
Please click on the above and let me know what the setting |
Before:
Click "Set as Interpreter" on the #-line. After:
Code is now broken. |
This is the expected behavior. If you don't want to change the interpreter, then please do not click this.
|
To handle cases like this, is there any option to disable this permanently displaying hint? |
No there isn't, you are welcome to create an issue for this. |
Environment data
VS Code version: 1.20.0
Python Extension version: 2018.1.0
Python Version: Python 3.5.2
OS and version: Ubuntu 16.04 LTS
Actual behavior
vscode/settings.json has
{
"python.pythonPath": "${workspaceFolder}/venv/bin/python3"
}
main.py starts with
#!/usr/bin/env python3
Expected behavior
"Set As Interpreter" is not displayed. If clicked, it keeps the currently active python3 (from venv).
Steps to reproduce:
The text was updated successfully, but these errors were encountered: