-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 ...
随机推荐
- SpringMVC简单实例(看起来有用)
SpringMVC简单实例(看起来有用) 参考: SpringMVC 基础教程 简单入门实例 - CSDN博客http://blog.csdn.net/swingpyzf/article/detail ...
- python MLP 神经网络使用 MinMaxScaler 没有 StandardScaler效果好
MLP 64,2 preprocessing.MinMaxScaler().fit(X) test confusion_matrix:[[ ...
- BEC listen and translation exercise 37
You're supposed to do that before 10.30 in the morning, but obviously, if it's an emergency, you can ...
- conda 里的 jupyter
1. 安装conda https://mirrors.tuna.tsinghua.edu.cn/anaconda/ 下载并安装. 2. 安装jupyter (1)在ananconda主环境安装:pip ...
- 每天一个linux命令(12):nl命令
版权声明更新:2017-05-16博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Linux下面的mv命令. 2. ...
- LOJ_#2720. 「NOI2018」你的名字 _后缀数组+主席树+倍增
题面: https://loj.ac/problem/2720 考虑枚举T串的每个后缀i,我们要做两件事. 一.统计有多少子串[i,j]在S中要求位置出现. 二.去重. 第二步好做,相当于在后缀数组上 ...
- [转]CSS3盒模型display:box详解
时间:2014-02-25来源:网络作者:未知编辑:RGB display:box;box-flex是css3新添加的盒子模型属性,它的出现可以解决我们通过N多结构.css实现的布局方式.经典的一个布 ...
- WCF中WcfSvcHost.exe如何禁止自动启动
今天同事问在一个WCF server的解决方案里调试时如何禁止Server自动启动. 经过调查发现, VS的工具WcfSvcHost会在调试时自动扫描工程里的WCF server, 然后启动起来. 如 ...
- 如何避免这个delete from tb_name不带条件的操作
那么,我们如何避免这个delete from tb_name不带条件的呢?其实是有办法的,但这只针对运维DBA或者DBA在操作时候有用,但对于PHP和JAVA程序,它的连接操作方式,就没办法避免了 s ...
- HDOJ1114(完全背包)
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const ...