Suf*_*ori 7 path python executable shebang
我已经下载了这个名为 pyAES.py 的脚本,并将它放在我的 Linux 桌面目录中的文件夹名称代码中,
根据这个例子, http://brandon.sternefamily.net/2007/06/aes-tutorial-python-implementation/
当我打字时,
./pyAES.py -e testfile.txt -o testfile_encrypted.txt
Run Code Online (Sandbox Code Playgroud)
应该执行文件 pyAES.py。但我收到此错误,
pi@raspberrypi ~/Desktop/Codes $ pyAES.py
-bash: pyAES.py: command not found
Run Code Online (Sandbox Code Playgroud)
ls -l
命令的输出是,
pi@raspberrypi ~/Desktop/Codes $ ls -l
total 16
-rw-r--r-- 1 pi pi 14536 Oct 8 10:44 pyAES.py
Run Code Online (Sandbox Code Playgroud)
这是之后的输出 chmod +x
pi@raspberrypi ~/Desktop/Codes $ chmod +x pyAES.py pi@raspberrypi ~/Desktop/Codes $
pi@raspberrypi ~/Desktop/Codes $ pyAES.py
-bash: pyAES.py: command not found
pi@raspberrypi ~/Desktop/Codes $
Run Code Online (Sandbox Code Playgroud)
和命令,chmod +x pyAES.py && ./pyAES.py
给出以下错误,
-bash: ./pyAES.py: /usr/bin/python2: bad interpreter: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我也试过在/usr/bin
目录中移动文件然后执行它,
pi@raspberrypi /usr/bin $ pyAES.py
-bash: /usr/bin/pyAES.py: /usr/bin/python2: bad interpreter: No such file or directory
pi@raspberrypi /usr/bin $
Run Code Online (Sandbox Code Playgroud)
我可以看到该文件存在于 /usr/bin 目录中,但它仍然给出没有这样的文件或目录的错误。
我想知道为什么 Linux 终端不执行 python 脚本?
看来你有一个写得很糟糕的shebang行。从你得到的错误中:
-bash: /usr/bin/pyAES.py: /usr/bin/python2: bad interpreter: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我会说你应该将第一行设置/usr/bin/pyAES.py
为
#!/correct/path/to/python
Run Code Online (Sandbox Code Playgroud)
其中/correct/path/to/python
可以从输出中找到:
type -P python
Run Code Online (Sandbox Code Playgroud)
它/usr/bin/python
(不是/usr/bin/python2
)在我的系统上。