As a lot of people I have both the 2.7 and 3.5 version of python. Some code is backwards-compatible, some are not. This is because of the lack of modules that exist for 2.7 but not for 3.5. I therefore have a fair bit of scripts that are 2.7 and a fair bit that are 3.5. The default of .py extensions is the 3.5 version of python in my computer. My question is as follows: How can you "tell" the script to use another version of python(2.7 for instance) rather than the default I am using(3.5). I heard about Shebang, but it is Linux only.
As mentioned in J. F. Sebastian's comment on this answer, the Python Launcher for Windows can select the Python version to run from a shebang line. According to the docs it's installed by default with Python 3.3 and later.
The windows shell does not use the shebang line to differentiate the file type. I am assuming you want to start your py file with different interpreter than default one.
You have 2 options:
If you do not mix your version 2.7 py files and 3.5 py files in one folder, you can use virtualenv http://docs.python-guide.org/en/latest/dev/virtualenvs/
That creates the isolated environment and is the very useful approach to isolation of any project.
If you have those files mixed, you just create .bat file which sets the path to your Python 2.7 interpreter and executes the py file.
来源:https://stackoverflow.com/questions/34289982/shebang-choose-what-version-of-python-a-script-is-going-to-run