Skip to content

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

Closed
gcp opened this issue Feb 9, 2018 · 21 comments
Closed
Labels
feature-request Request for new features or functionality

Comments

@gcp
Copy link

gcp commented Feb 9, 2018

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:

  • Click "Set as interpreter" on the #! line
  • See interpreter get set to system python3 instead of venv one.
@DonJayamanne
Copy link

Unfortunately this feature is not supported. You need to specify the path in the settings.json.
You can move the more over the shebang and you'll get a coffee lense shooting l allowing you change the interpreter.

@gcp
Copy link
Author

gcp commented Feb 9, 2018

You misunderstand. As described in the "Actual Behavior", the interpreter is already set in settings.json.

@DonJayamanne DonJayamanne added feature-request Request for new features or functionality closed-wontfix area-debugging labels Feb 9, 2018
@DonJayamanne DonJayamanne reopened this Feb 9, 2018
@DonJayamanne
Copy link

Got it.

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug awaiting 1-verification and removed closed-wontfix area-debugging feature-request Request for new features or functionality labels Feb 9, 2018
@gcp
Copy link
Author

gcp commented Feb 9, 2018

Basically, it should not offer to set the interpreter if the settings already have a non-default one.

@DonJayamanne
Copy link

See interpreter get set to system python3 instead of venv 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.

Basically, it should not offer to set the interpreter if the settings already have a non-default one.

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.

@DonJayamanne DonJayamanne added feature-request Request for new features or functionality closed-wontfix and removed awaiting 1-verification bug Issue identified by VS Code Team member as probable bug labels Feb 9, 2018
@gcp
Copy link
Author

gcp commented Feb 9, 2018

point to the system bedroom, as that's what's in the shebang.

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.

@gcp
Copy link
Author

gcp commented Feb 9, 2018

VSCode seems to consider that line from it's own environment, not from the environment in the venv that is being used.

@gcp
Copy link
Author

gcp commented Feb 9, 2018

...and that matters because a venv will change PATH, as explained.

@DonJayamanne DonJayamanne reopened this Feb 9, 2018
@DonJayamanne
Copy link

DonJayamanne commented Feb 9, 2018

I'm sorry, but I don't quite understand the issue,

Set as Interpreter hint displayed even when non-default setting is active

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.

No. It will use the first one that is in the PATH

  • Please could you tell me how you are validating this?
  • Are you running some python code in the terminal are you debugging, or are you creating terminal and checking the path?
  • Please could you debug the following python file or run it from the terminal using the Run Python File in Terminal command:
import sys
print(sys.executable)

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster and removed closed-wontfix feature-request Request for new features or functionality labels Feb 9, 2018
@gcp
Copy link
Author

gcp commented Feb 9, 2018

Please could you tell me how you are validating this?

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.

Are you running some python code in the terminal are you debugging, or are you creating terminal and checking the path?

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.

Please could you debug the following python file or run it from the terminal using the Run Python File in Terminal command:

Terminal

morbo@mozwell:~/git/reptools$ source venv/bin/activate
(venv) morbo@mozwell:~/git/reptools$ python test.py
/home/morbo/git/reptools/venv/bin/python

Debug mode in VSCode

/home/morbo/git/reptools/venv/bin/python3

@gcp
Copy link
Author

gcp commented Feb 9, 2018

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.

@DonJayamanne
Copy link

but it won't give the correct result for determining what the bang line actually refers to.

As I mentioned earlier, the shabang is something that is not supported by VS Code when debugging or the like.
See here for an explanation #497 (comment)

@DonJayamanne DonJayamanne added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Feb 9, 2018
@gcp
Copy link
Author

gcp commented Feb 9, 2018

I understand, but then it shouldn't show a permanent "Set as Interpreter" either.

@gcp
Copy link
Author

gcp commented Feb 9, 2018

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.

@DonJayamanne
Copy link

but then it shouldn't show a permanent "Set as Interpreter" either.

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.

@gcp
Copy link
Author

gcp commented Feb 9, 2018

if users wish to change the value to something that's defined in the shebang

But we just established that this does not work.

@DonJayamanne DonJayamanne added closed-duplicate and removed info-needed Issue requires more information from poster labels Feb 9, 2018
@DonJayamanne DonJayamanne reopened this Feb 9, 2018
@DonJayamanne
Copy link

But we just established that this does not work.

Please click on the above and let me know what the setting "python.pythonPath" points to in your workspace settings (settings.json).

@gcp
Copy link
Author

gcp commented Feb 9, 2018

Before:

{
    "python.pythonPath": "${workspaceFolder}/venv/bin/python3"
}

Click "Set as Interpreter" on the #-line.

After:

{
    "python.pythonPath": "/usr/bin/python3"
}

Code is now broken.

@DonJayamanne
Copy link

This is the expected behavior. If you don't want to change the interpreter, then please do not click this.
As mentioned earlier:

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.

@theFroh
Copy link

theFroh commented Mar 15, 2018

To handle cases like this, is there any option to disable this permanently displaying hint?

@DonJayamanne
Copy link

is there any option to disable this permanently displaying hint

No there isn't, you are welcome to create an issue for this.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

3 participants