我在Windows下写的python小测试程序,传到Fedora上运行,结果出现如下错误:
[ycxie@fedora Workspace]$ ./hello.py bash: ./hello.py: /usr/bin/python3^M: bad interpreter: No such file or directory
python3后面的换行,应该是多了不该有的字符。我们file一下看看,进一步验证了。
[ycxie@fedora Workspace]$ file hello.py hello.py: Python script, UTF-8 Unicode text executable, with CRLF line terminators
接下来我们就用vim干掉它吧。用vim打开hello.py,输入“: set ff”或者“:set fileformat”查看文件格式,结果看到“fileformat=dos”。最后我们输入“:set ff=unix”或者“:set fileformat=unix”,保存,退出即可。
[ycxie@fedora Workspace]$ file hello.py hello.py: Python script, UTF-8 Unicode text executable
接下来,我们运行./hello.py顺利通过,至此大功告成~