How to execute python file in linux

前端 未结 7 667
长情又很酷
长情又很酷 2020-12-08 14:27

I am using linux mint, and to run a python file I have to type in the terminal: python [file path], so is there way to make the file executable, and make it run

7条回答
  •  庸人自扰
    2020-12-08 15:00

    You have to add a shebang. A shebang is the first line of the file. Its what the system is looking for in order to execute a file.

    It should look like that :

    #!/usr/bin/env python
    

    or the real path

    #!/usr/bin/python
    

    You should also check the file have the right to be execute. chmod +x file.py

    As Fabian said, take a look to Wikipedia : Wikipedia - Shebang (en)

提交回复
热议问题