![](/img/trans.png)
[英]A shell script initiated by Python's os.system fails to run, but the script do run when called from terminal
[英]run Python script as a system command from terminal like “ls” in linux OS
我有一個python腳本,我想從linux中的終端運行,而不在開始時使用“ python”關鍵字。 例如,我的腳本名稱是helloworld.py,它從終端接受2個參數。 我想從終端以“ helloworld”的形式運行此腳本,而不是“ python helloworld.py”
為了使文件可執行,請重命名並更改訪問權限的模式,例如:
$ mv helloworld.py helloworld
$ chmod +x helloworld
並將文件的第一行編輯為shebang :
#!/usr/bin/env python
從外殼程序運行它至少有三種方法:
./helloworld
或/path/to/helloworld
PATH
上的目錄,例如/usr/local/bin
或~/bin
PATH
以添加目錄,例如export PATH=$PATH:/to/dir
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.