当前位置: 首页 > 工具软件 > bash.py > 使用案例 >

Ubuntu执行脚本报错-bash: ./send.py: /usr/bin/python: bad interpreter: Permission denied

孙熠彤
2023-12-01

在Ubuntu系统终端中,使用命令行如下命令行运行*.py文件:
执行脚本报错

root@ubuntu:/usr/bin/python# chmod a+x send.py
root@ubuntu:/usr/bin/python# ./send.py
-bash: ./send.py: /usr/bin/python: bad interpreter: Permission denied

参考 :
解决办法

第一个就是赋予文件可执行性:

$ chmod +x tools/demo.py
第二种方法就是使用这样的调用方式:

$ python tools/demo.py

2、sudo rm -rf /usr/bin/python
sudo ln -s /usr/bin/python2.6 /usr/bin/python

-bash: ./bak_1.py: /usr/bin/python^M: bad interpreter: 没有那个文件或目录

[root@localhost training]# vi bak_1.py 
利用如下命令查看文件格式
 :set ff 或 :set fileformat
可以看到如下信息
       fileformat=dos 或 fileformat=unix
利用如下命令修改文件格式
:set ff=unix 或 :set fileformat=unix
:wq (存盘退出)

报错2、./a.py 执行,报错“-bash: ./a.py: /usr/bin/python^M: bad interpreter: No such file or directory”

根据错误信息,发现文件是msdos格式的,行尾是\r\n。
转换成unix格式后(sed -i ‘s#\r##’ a.py),问题解决。

参考链接 :
https://blog.csdn.net/weixin_34199405/article/details/92618134

 类似资料: