Dealing with Multiple Python Versions— do not run independently

后端 未结 5 1314
无人共我
无人共我 2021-01-14 03:09

I have Python 2.7 (my preferred version) and 3.3 (version used in my Programming class) installed on my computer (OS: Windows 7). Until a certain point, they worked fine ind

5条回答
  •  余生分开走
    2021-01-14 03:47

    You should focus on the Windows specific features here. The #! way was usefull only for Unix based operating systems until recently.

    Python 3.3 introduced Python Launcher for Windows for exactly that purpose. When Python 3.3 was installed on your machine, the installer copied py.exe and pyw.exe launchers into c:\Windows, and the .py and .pyw extensions were associated with the launchers.

    This way, if the .py file is not launched explicitly via Python interpreter, the Python Launcher is used. You can also explicitly launch py script.py.

    If there is no information about Python version, the highest Python 2.x is used. There are two ways how to tell the launcher that you want to launch Python 3: 1) explicitly py -3 script.py, 2) write #!python3 to the first line inside the script.py.

    The wanted Python version can be more detailed (to execute the specific version of Python). See the mentioned doc. I have also summarized my surprise with that situation in the article Do you know the "Python Launcher for Windows"? at Experts Exchange.

提交回复
热议问题