-bash: ./bak_1.py: /usr/bin/python^M: bad interpreter: 没有那个文件或目录
在Windows的PyCharm中编写了一个Python文件,然后上传至CentOS中,已经添加执行权限,但是仍然会报如下的错误:

代码如下:
#!/usr/bin/python
# -*- coding:UTF-8 -*- #必须在第一行或者第二行显示中文
# Filename:bak_1.py import os
import time
#第一步:需要备份的文件和目录由一个列表指定
source=['/code/study/var.py','/code/study/helloworld.py']
#第二步:备份应该保存在主备份目录中。
target_dir='/backup'
#第三步:文件备份成一个zip文件。
#第四步:zip存档的名称是当前的日期和时间。
target =target_dir + target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
#第五步:我们使用标准的zip命令,它通常默认地随Linux/Unix发行版提供。
zip_commamd="zip -qr '%s' %s" %(target,' '.join(source)) #开始执行
if os.system(zip_commamd) == 0:
print '备份结束',target
else:
print '备份失败'
使用
python training/bak_1.py
能够正常的执行程序。说明代码段是没有问题的。同时查看pyhton的目录,的确在/usr/bin目录下,也没有问题。查看了网络的资源才知道是Windows上传时候的问题。
请参考http://www.suiyiwen.com/question/4185。
我的解决办法是
[root@localhost training]# vi bak_1.py
利用如下命令查看文件格式
:set ff 或 :set fileformat
可以看到如下信息
fileformat=dos 或 fileformat=unix
利用如下命令修改文件格式
:set ff=unix 或 :set fileformat=unix
:wq (存盘退出)
之后就可以正常的执行文件了。
-bash: ./bak_1.py: /usr/bin/python^M: bad interpreter: 没有那个文件或目录的更多相关文章
- /usr/bin/python^M: 解释器错误: 没有那个文件或目录
遇见问题 因为linux在虚拟机中,所以就在本地敲python代码,敲完后再拿到虚拟机去执行,再输入./filename.py时,就遇到这样的一个问题: bash: ./filename.py: /u ...
- 解决:执行python脚本,提示错误:/usr/bin/python^M: 解释器错误: 没有那个文件或目录。
执行python脚本,提示错误: /usr/bin/python^M: 解释器错误: 没有那个文件或目录. 产生错误原因: \r字符被显示为^M,这时候只需要删除这个字符就可以了. Linux环境下: ...
- window下编写python脚本在linux下运行出错 usr/bin/python^M: bad interpreter: No such file or directory
今天在windows下使用notepad++写了个python脚本,传到linux服务器执行后提示:-bash: ./logger.py: usr/bin/python^M: bad interpre ...
- python /usr/bin/python^M: bad interpreter: No such file
今天在WingIDE下写了个脚本,传到服务器执行后提示: -bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No suc ...
- 运行python “没有那个文件或目录3” 或 “/usr/local/bin/python3^M: bad interpreter: 没有那个文件或目录” 错误
原因 如果使用的是#!/usr/local/bin/python3这种方式,就会出现 “/usr/local/bin/python3^M: bad interpreter: 没有那个文件或目录” 错误 ...
- -bash: ./radar.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录
运行shell脚本时,报下面这个错误: -bash: ./radar.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录 错误分析: 因为操作系统是windows, ...
- -bash: ./job.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录
昨天在windows下用写字板写了个shell脚本,使用winscp上传到linux上运行的时候发现运行不了,提示-bash: ./job.sh: /bin/sh^M: bad interpreter ...
- /bin/sh^M: bad interpreter:没有那个文件或目录解决
/bin/sh^M: bad interpreter:没有那个文件或目录解决 执行脚本时发现如下错误: /bin/sh^M: bad interpreter: 没有那个文件或目录 错误分析: ...
- bash: ./vmware-install.pl: /user/bin/perl: 坏的解释器:没有那个文件或目录
----------------安装VMwere Tools------------------------bash: ./vmware-install.pl: /usr/bin/perl: bad ...
随机推荐
- php设计模式课程---4、观察者模式的好处是什么
php设计模式课程---4.观察者模式的好处是什么 一.总结 一句话总结: 方便选择之后去控制监听的板块数:比如选择男士之后,我可以决定监听广告里面的第二和第三板块. 1.为什么有观察者模式? 错误理 ...
- hdu 1503 Advanced Fruits(最长公共子序列)
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- html网页小图标
<link rel="shortcut icon" href="../image/favicon.ico"/>
- Tomcat_异常_01_Setting property 'source' to 'org.eclipse.jst.jee.server:AWeiXin_QiYe_Demo' did not find a matching property
关于解决方法: 1.解决Setting property 'source' to 'org.eclipse.jst.jee.server的问题 2.eclipse中server location为灰色 ...
- php导出内容到txt并自动弹出下载文件
php将内容保存到txt文件中,并自动弹出下载文件窗口的方法: $id=array('我爱学习网http://www.5ixuexiwang.com','汇享在线工具箱http://tool.huix ...
- leetcode 162 Find Peak Element(二分法)
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- 04 - Django应用第一步
知识点 1) 创建项目命令 以及项目结构介绍 2) 创建应用程序命令 应用, 项目的区别 以及应用程序结构 3) 启动项目命令 4) URLs的编写 include()的使用 get发送参数的格式 u ...
- linux命令学习笔记(16):which命令
我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索: which 查看可执行文件的位置. whereis 查看文件的位置. locate 配合数据库查看文件位置. f ...
- 【leetcode刷题笔记】Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- ffmpeg推流命令参数记录
列出我们本机的设备:ffmpeg -list_devices true -f dshow -i dummy .\ffmpeg -r 25 -f dshow -s 640*480 -i video=&q ...