-bash: ./main.py: /usr/bin/python3^M: bad interpreter: No such file or directory

[root@]# ./main.py
-bash: ./main.py: /usr/bin/python3^M: bad interpreter: No such file or directory
[root@i]# ./test.php
: No such file or directory
./test.php: line 2: $'\r': command not found
./test.php: line 3: =: command not found
./test.php: line 3: $'\r': command not found
./test.php: line 4: syntax error near unexpected token `('

之所以出现上述问题,可能是不同系统编码格式引起的,你的这个文件也许是在window系统编写,然后上传到了Linux系统。

解决方案如下

首先打开文件

vi main.py

输入如下命令

:set ff
# 或者
:set fileformat

文件末端会显示如下信息

fileformat=dos 
# 或者是 
fileformat=unix 

如果是fileformat=dos,输入如下命令

:set ff=unix 
# 或者 
:set fileformat=unix 

最后保存退出

:wq
# 要是无法退出,可以强制保存退出
:wq!

再执行文件看看,是否问题已经解决