从 bash 运行 Python 脚本:找不到命令错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17157359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:42:53  来源:igfitidea点击:

Running Python script from bash: Command not found error

pythonlinuxbashshell

提问by Vignesh

I Get command not found error. 0 and $filestem are the two args and I had the following in a script. And when i execute the script, I get command not found.

我获取命令未找到错误。0 和 $filestem 是两个参数,我在脚本中有以下内容。当我执行脚本时,我找不到命令。

echo -e "Enter the file stem name"
read filestem
python gen_par_final.py 0 $filestem

The input files, the python script and the bash script are all in the same folder. the python script works at the command promt as such but not inside the script. Is there any path to be set or something that will resolve the problem?

输入文件、python 脚本和 bash 脚本都在同一个文件夹中。python 脚本在命令提示符下工作,但不在脚本内。是否有任何要设置的路径或可以解决问题的方法?

回答by Sagar Rakshe

This could work

这可以工作

  1. Insert this #! /usr/bin/Pythonat the top of gen_par_final.pyfile.
    (It's usually /usr/bin/pythonyou need to check out how it's capital P)

  2. Make gen_par_final.pyexecutable.
    $ chmod +x gen_par_final.py

  3. Edit your shell script.

    echo -e "Enter the file stem name"
    read filestem
    ./gen_par_final.py 0 $filestem

  1. 将其插入文件#! /usr/bin/Python顶部gen_par_final.py
    (通常/usr/bin/python你需要看看它的资本如何P

  2. 使gen_par_final.py可执行。
    $ chmod +x gen_par_final.py

  3. 编辑您的 shell 脚本。

    echo -e "Enter the file stem name"
    read filestem
    ./gen_par_final.py 0 $filestem

回答by tike

could /path/to/python ./gen_par_final.py 0 ${filestem}solve this?

/path/to/python ./gen_par_final.py 0 ${filestem}解决这个问题吗?

I assume you checked for spelling errors?

我假设您检查了拼写错误?