别名在.sh脚本中运行错误的python解释器[关闭]

问题描述 投票:0回答:2
我正在尝试从.sh脚本运行.py脚本。我在Windows上运行GitBash,并在shell脚本中使用以下行运行python文件:

#!/bin/bash python3 Mycode.py

它运行时,出现以下错误消息:

$ Mycode.sh /c/Users/tmsta/documents/coding/python/Mycode.sh: line 2: /c/Users/tmsta/AppData/Local/Microsoft/WindowsApps/python3: Permission denied

我注意到它所引用的python解释器是错误的解释器。当我在文件浏览器中单击它时,它会弹出Windows应用商店中的python,这不是我想要的。

我跑步时

python3 Mycode.py

在终端本身的脚本之外,它使用正确的python解释器。当我将脚本更改为:

#!/bin/bash winpty /c/correct/python/interpreter/location/python.exe Mycode.py

它运行正确的解释器。那么如何获取python3别名以在shell脚本中运行正确的解释器?    
python bash shell alias
2个回答
0
投票
    在文件job.sh中,放入此
  • #!/bin/sh python filename.py
      执行此命令以使脚本可运行:chmod u+x job.sh
  • 运行:./job.sh

  • 0
    投票
    将文件中的路径更改为完整路径

    #!/bin/bash python3 /path_to_script/filename.py

    © www.soinside.com 2019 - 2024. All rights reserved.