Linux上运行python出现错误“/usr/bin/env: python3: No such file or directory"

Posted andy_0212

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux上运行python出现错误“/usr/bin/env: python3: No such file or directory"相关的知识,希望对你有一定的参考价值。

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 line ending (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 dos2unix:

sudo dos2unix /usr/local/bin/casperjs (你的文件)

or sed:

sudo sed -i -e ‘s/
$//‘ /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.

以上是关于Linux上运行python出现错误“/usr/bin/env: python3: No such file or directory"的主要内容,如果未能解决你的问题,请参考以下文章

在PyCharm上正常运行的python程序在linux服务器上运行就报错

在PyCharm上正常运行的python程序在linux服务器上运行就报错

在PyCharm上正常运行的python程序在linux服务器上运行就报错

无法在 Linux 上构建 PYQT

准系统 SWIG python C 接口在 OSX+clang 上出现段错误,而不是在 Linux+gcc 中

使用子进程在 Windows 上运行 Python 脚本