簡體   English   中英

輸入:未找到使用 shell 腳本運行 python 的命令

[英]Input: command not found running python with shell script

我只是使用這個 shell 腳本在 ssh 中運行我的 python 代碼並且它正在工作,但我想在我的本地機器上運行它並且以某種方式使用 Windows 和 git-bash 它無法識別我的代碼。 我認為問題出在 shell 腳本而不是 python 代碼中,因為它之前運行正確。

錯誤:

SyntaxError: invalid syntax 
line 1: import: command not found 
line 3: syntax error near unexpected token `(`
line 3: 'def get_stdin():'

劇本:

if [[ "$OSTYPE" =~ ^msys ]]; then
  dos2unix *.sh // I've put this in and taken it out and I don't think it does anything 
  py -3 $*
else
  dos2unix *.sh
  python3
fi
./make_voc.py

相關Python代碼

import sys

def get_stdin():
    text = sys.stdin.read()

命令

cat INPUTFILE | ./shellscript.sh > OUTPUTFILE
  1. 確保您的代碼(Shell 和 Python)是 DOS 格式。
  2. 將您的 python 代碼稱為 python3./make_voc.py

如果仍然無法正常工作,請確保您可以在 Shell 腳本中運行 Hello World 代碼,並在您在 Windows 中創建的新 Python 代碼文件中單獨運行(不是從 Linux/Unix 復制的)。 在你的兩個代碼文件都工作之后,然后從你的 shell 代碼調用 python 代碼。

沒有'如果'......保持簡單。 例如在 myShell.sh 中:(只有兩行):

從 myShell.sh 回顯 Hello World

python3 myPython.py

您應該會在屏幕上看到兩條 Hello World 消息。

If your shell interpreter doesn't work in your cmd window then you might find it useful to have Windows subsystem for Linux. Refer to canada.ca/en/revenue-agency.html Default bash in Window 10 is not fully functional like real Bash在Linux。所以它不能調用你的python代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM