Turn an application or script into a shell command

后端 未结 6 1942
走了就别回头了
走了就别回头了 2021-02-06 11:11

When I want to run my python applications from commandline (under ubuntu) I have to be in the directory where is the source code app.py and run the application with command
<

6条回答
  •  我寻月下人不归
    2021-02-06 11:39

    1. Add a shebang line at the beginning of your file:

      #!/usr/bin/env python
      
    2. Make your file executable by calling

      chmod +x app.py
      

      in the shell.

    3. Move it to some location included in the PATH environment variable and rename it to app. Alternatively, add the path of the directory containing app to the PATH environment variable by adding the line

      export PATH=$PATH:/path/to/app
      

      to your .bash_profile.

提交回复
热议问题