Should I put #! (shebang) in Python scripts, and what form should it take?

前端 未结 12 1206
感动是毒
感动是毒 2020-11-22 01:27

Should I put the shebang in my Python scripts? In what form?

#!/usr/bin/env python 

or



        
12条回答
  •  眼角桃花
    2020-11-22 01:59

    When I installed Python 3.6.1 on Windows 7 recently, it also installed the Python Launcher for Windows, which is supposed to handle the shebang line. However, I found that the Python Launcher did not do this: the shebang line was ignored and Python 2.7.13 was always used (unless I executed the script using py -3).

    To fix this, I had to edit the Windows registry key HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.File\shell\open\command. This still had the value

    "C:\Python27\python.exe" "%1" %*
    

    from my earlier Python 2.7 installation. I modified this registry key value to

    "C:\Windows\py.exe" "%1" %*
    

    and the Python Launcher shebang line processing worked as described above.

提交回复
热议问题