run a python script in terminal without the python command

后端 未结 4 1446
梦如初夏
梦如初夏 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条回答
  •  难免孤独
    2020-12-02 07:08

    You use a shebang line at the start of your script:

    #!/usr/bin/env python
    

    make the file executable:

    chmod +x arbitraryname
    

    and put it in a directory on your PATH (can be a symlink):

    cd ~/bin/
    ln -s ~/some/path/to/myscript/arbitraryname
    

提交回复
热议问题