Make Python script globally executable

前端 未结 2 534
独厮守ぢ
独厮守ぢ 2020-12-17 03:15

Let\'s say I\'ve got this one-line Python module called say_hello.py.

print \'Hello World\'

How can I make the script executab

相关标签:
2条回答
  • 2020-12-17 03:35

    General *nix answer

    First line of script should look something like:

    #!/usr/bin/python
    

    although the exact path may be different on your system. Then, make the script executable and put it somewhere in your PATH.

    0 讨论(0)
  • 2020-12-17 03:57

    Add as the first line of your script:

    #!/usr/bin/env python
    

    or, for a python3 script:

    #!/usr/bin/env python3
    

    The shell (actually the kernel) will use the first Python/Python3 interpreter found in your $PATH.

    0 讨论(0)
提交回复
热议问题