: bad interpreter: python 中没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16757349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
: bad interpreter: No such file or directory in python
提问by Deepak
I originally coded in python IDE on windows. Now when I pasted my code in a file on Linux server. Now when I run the script, it gives me this error:
我最初在 Windows 上的 python IDE 中编码。现在,当我将代码粘贴到 Linux 服务器上的文件中时。现在当我运行脚本时,它给了我这个错误:
bad interpreter: No such file or directory
错误的解释器:没有这样的文件或目录
Please tell how to resolve this error.
请告诉如何解决此错误。
采纳答案by John La Rooy
Probably you have \r\nline endings, where \ris carriage return and \nis newline
可能你有\r\n行尾,\r回车在哪里,\n换行在哪里
That means that the first line might be like this
这意味着第一行可能是这样的
#!/usr/bin/env python\r\n
or
或者
#!/usr/bin/python\r\n
so the shell is trying to run the command python\r
所以 shell 正在尝试运行命令 python\r
回答by Cairnarvon
You're probably using the #!pythonhashbang convention that's inexplicably popular among Windows users. Linux expects a full path there. Use either #!/usr/bin/pythonor (preferably) #!/usr/bin/env pythoninstead.
您可能正在使用#!python在 Windows 用户中莫名流行的hashbang 约定。Linux 需要一个完整的路径。使用#!/usr/bin/python或(最好)#!/usr/bin/env python代替。

