run a python script in terminal without the python command

后端 未结 4 1444
梦如初夏
梦如初夏 2020-12-02 06:37

I have a python script let\'s name it script1.py. I can run it in the terminal this way:

python /path/script1.py
...

but I want to run like

4条回答
  •  旧时难觅i
    2020-12-02 07:13

    You need to use a hashbang. Add it to the first line of your python script.

    #! 
    

    Then change the file permissions, and add the executing permission.

    chmod +x 
    

    And finally execute it using

    ./
    

    If its in the current directory,

提交回复
热议问题