Python scripts in /usr/bin

后端 未结 5 495
野的像风
野的像风 2021-02-04 04:07

I\'m writing a pretty basic application in python (it\'s only one file at the moment). My question is how do I get it so the python script is able to be run in /usr/bin without

5条回答
  •  别跟我提以往
    2021-02-04 04:34

    Simply strip off the .py extension by renaming the file. Then, you have to put the following line at the top of your file:

    #!/usr/bin/env python
    

    env is a little program that sets up the environment so that the right python interpreter is executed.

    You also have to make your file executable, with the command

    chmod a+x htswap
    

    And dump it into /usr/local/bin. This is cleaner than /usr/bin, because the contents of that directory are usually managed by the operating system.

提交回复
热议问题