Why do people write #!/usr/bin/env python on the first line of a Python script?

后端 未结 21 1756
刺人心
刺人心 2020-11-21 06:16

It seems to me like the files run the same without that line.

21条回答
  •  逝去的感伤
    2020-11-21 07:05

    Perhaps your question is in this sense:

    If you want to use: $python myscript.py

    You don't need that line at all. The system will call python and then python interpreter will run your script.

    But if you intend to use: $./myscript.py

    Calling it directly like a normal program or bash script, you need write that line to specify to the system which program use to run it, (and also make it executable with chmod 755)

提交回复
热议问题