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

Support shebang #!/usr/bin/env python{2,3} #497

Closed
citizenrich opened this issue Dec 30, 2017 · 8 comments
Closed

Support shebang #!/usr/bin/env python{2,3} #497

citizenrich opened this issue Dec 30, 2017 · 8 comments

Comments

@citizenrich
Copy link

citizenrich commented Dec 30, 2017

One of the best practices for managing Python versions across operating systems is the shebang '#!/usr/bin/env python3'. To get around the lack of support for this practice, it seems that the user has to add changes to each individual workspace to set Python versions. Note that setting the 'Python: Select interpreter' is also ignored by VSCode.

It would be helpful if maintainers were transparent about whether they have interest or will accept a PR from someone else contributing a fix. This issue was closed in the upstream repo multiple times and not left as open.

Actual behavior

shebang is ignored

Expected behavior

shabang is respected

Steps to reproduce:

Create file:

#!/usr/bin/env python3
import sys
print(sys.executable)

Run it.

Environment data

VS Code version: 1.19.1
Python Extension version: 0.9.1
Python Version: 3.6.4
OS and version: macOS 10.13.2

@brettcannon
Copy link
Member

There should be a code lens in the latest version of the extension that you can click to switch the selected Python interpreter to the interpreter in the shebang. But we purposefully don't not automatically select what the shebang sets because what someone set for their code may not be what you want to use (e.g. you might choose Python 3.5 but I want to run against 3.6, or you hard-coded the path on Linux and thus doesn't work on Windows).

@citizenrich
Copy link
Author

citizenrich commented Jan 3, 2018

Thanks for the helpful info.

On setting the code lens, if you mean 'Python: Select Interpreter', that setting is not respected. See attached. The version selected was /usr/local/bin/python3. What was used was /usr/bin/python.)

output

@DonJayamanne DonJayamanne reopened this Jan 3, 2018
@DonJayamanne
Copy link

DonJayamanne commented Jan 3, 2018

The version selected was /usr/local/bin/python3.

Please could you go into .vscode/settings.json (workspace settings) and provide us with the value for the setting python.pythonPath.
Thanks

@brettcannon brettcannon added info-needed Issue requires more information from poster feature-extension bug Issue identified by VS Code Team member as probable bug and removed closed-wontfix labels Jan 3, 2018
@citizenrich
Copy link
Author

By 'version selected' re: my screenshot above, I mean the version selected in the 'Python: Select Interpreter'.

I've also just checked the local workspace, added it, and it does not work in a local workspace nor is it respected in global settings.

@DonJayamanne DonJayamanne reopened this Jan 3, 2018
@DonJayamanne
Copy link

@citizenrich
I understand, but to help you, I need to see the contents of your workspace settings.
Thanks

@citizenrich
Copy link
Author

Sure. So, sorry if I've not been clear. The 'Python: Select Interpreter' is already set.

On workspace settings, I've tried it with no workspace settings. And with (macOS homebrew installed Python 3):

{
    "python.pythonPath": "/usr/local/bin/python3"
}
richard@thrillride:~/Dropbox/notes$ which python3
/usr/local/bin/python3

@DonJayamanne
Copy link

Ok, looks like you are not using the Python extension to run the python program. You seem to be using another extension such as Code Runner.
I'm closing this issue as the output of the output panel is a clear indication of the above fact.

Solution is to use the debug menu or the corresponding debug icons (F5 or CTRL+F5 or similar).

@DonJayamanne DonJayamanne added closed-invalid and removed info-needed Issue requires more information from poster closed-wontfix bug Issue identified by VS Code Team member as probable bug labels Jan 3, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 12, 2018
@microsoft microsoft unlocked this conversation Dec 14, 2018
@spencerhakim
Copy link

we purposefully don't not automatically select what the shebang sets because what someone set for their code may not be what you want to use

As I said in #3689, this is perfectly reasonable default behavior, but the option to enable such automatic functionality would be great.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants