编程语言
首页 > 编程语言> > python – 没有这样的文件或目录,但我可以看到它!

python – 没有这样的文件或目录,但我可以看到它!

作者:互联网

我正在尝试使用winSCP在无头Raspberry PI上运行python脚本并收到以下错误消息:

Command '"./areadetect_movie_21.py"'
failed with return code 127 and error message
/usr/bin/env: python
: No such file or directory.

当我尝试从终端运行时,我得到:

: No such file or directory.

我尝试了一个类似的python脚本,在同一个目录中,使用相同的python shebang,相同的权限和使用相同的用户pi,它的工作原理.

我也做了一个ls,我可以看到该文件,所以我不知道为什么它不会运行.

解决方法:

AskUbuntu开始,回答Gilles

If you see the error “: No such file or directory” (with nothing before the colon), it means that your shebang line has a carriage return at the end, presumably because it was edited under Windows (which uses CR,LF as a line separator). The CR character causes the cursor to move back to the beginning of the line after the shell prints the beginning of the message and so you only get to see the part after CR which ends the interpreter string that’s part of the error message.

Remove the CR: the shebang line needs to have a Unix 07002 (linefeed only). Python itself allows CRLF line endings, so the CR characters on other lines don’t hurt. Shell scripts on the other hand must be free of CR characters.

To remove the Windows line endings, you can use 07003:

sudo dos2unix /usr/local/bin/casperjs

or sed:

sudo sed -i -e ‘s/\r$//’ /usr/local/bin/casperjs

If you must edit scripts under Windows, use an editor that copes with Unix line endings (i.e. something less brain-dead than Notepad) and make sure that it’s configured to write Unix line endings (i.e. LF only) when editing a Unix file.

标签:python,executable,ls,shebang,newlines
来源: https://codeday.me/bug/20190809/1628414.html