How to execute python file in linux

前端 未结 7 554
长情又很酷
长情又很酷 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:05

    I suggest that you add

    #!/usr/bin/env python
    

    instead of #!/usr/bin/python at the top of the file. The reason for this is that the python installation may be in different folders in different distros or different computers. By using env you make sure that the system finds python and delegates the script's execution to it.

    As said before to make the script executable, something like:

    chmod u+x name_of_script.py
    

    should do.

    0 讨论(0)
提交回复
热议问题