How to execute python file in linux

前端 未结 7 660
长情又很酷
长情又很酷 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 14:44

    yes there is. add

    #!/usr/bin/env python

    to the beginning of the file and do

    chmod u+rx

    assuming your user owns the file, otherwise maybe adjust the group or world permissions.

    .py files under windows are associated with python as the program to run when opening them just like MS word is run when opening a .docx for example.

提交回复
热议问题