Shebang/choose what version of Python a script is going to run

前端 未结 2 675
盖世英雄少女心
盖世英雄少女心 2021-01-25 14:31

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

相关标签:
2条回答
  • 2021-01-25 14:33

    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:

    1. 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.

    2. 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.

    0 讨论(0)
  • 2021-01-25 14:38

    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.

    0 讨论(0)
提交回复
热议问题