Purpose of #!/usr/bin/python3

前端 未结 6 709
遇见更好的自我
遇见更好的自我 2020-11-30 16:53

I have noticed this in a couple of scripting languages, but in this example, I am using python. In many tutorials, they would start with #!/usr/bin/python3 on t

6条回答
  •  再見小時候
    2020-11-30 17:29

    To clarify how the shebang line works for windows, from the 3.7 Python doc:

    • If the first line of a script file starts with #!, it is known as a “shebang” line. Linux and other Unix like operating systems have native support for such lines and they are commonly used on such systems to indicate how a script should be executed.
    • The Python Launcher for Windows allows the same facilities to be used with Python scripts on Windows
    • To allow shebang lines in Python scripts to be portable between Unix and Windows, the launcher supports a number of ‘virtual’ commands to specify which interpreter to use. The supported virtual commands are:
      • /usr/bin/env python
        • The /usr/bin/env form of shebang line has one further special property. Before looking for installed Python interpreters, this form will search the executable PATH for a Python executable. This corresponds to the behaviour of the Unix env program, which performs a PATH search.
      • /usr/bin/python
      • /usr/local/bin/python
      • python

提交回复
热议问题