windows和linux的转行符不同导致的Python无法执行的解决方法

来源:互联网 发布:巨人网络涨停 编辑:程序博客网 时间:2024/06/01 08:47

Python的代码从Windows传到Linux里,看到已经有x权限了,就直接通过`./xxx.py`来运行程序,结果报错:

bash: ./Karrigell.py: /usr/bin/python^M: bad interprter: No such file or directory

于是查了下文件属性:

[root@localhost Karrigell-3.1.1]# file Karrigell.py 
Karrigell.py: Python script, ASCII text executable, with CRLF line terminators
[root@localhost Karrigell-3.1.1]# vim Karrigell.py 

#######################################

于是vim打开程序,设置fileformat :

: set ff=unix

于是就可以通过./xxx.py运行了。

########################################
[root@localhost Karrigell-3.1.1]# file Karrigell.py 
Karrigell.py: Python script, ASCII text executable


0 0
原创粉丝点击