Python 谢邦元';行不通

Python 谢邦元';行不通,python,python-2.x,shebang,Python,Python 2.x,Shebang,我已经编写了一个小python脚本,但bash不会执行它: #!/usr/bin/python ''' Created on Dec 19, 2014 ''' import subprocess if __name__ == '__main__': p = subprocess.Popen('df -h', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out,err = p.communicat

我已经编写了一个小python脚本,但bash不会执行它:

#!/usr/bin/python

'''
Created on Dec 19, 2014


'''
import subprocess


if __name__ == '__main__':
    p = subprocess.Popen('df -h', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    out,err = p.communicate()
    for o in out.splitlines():
        if('rootfs' in o):
            print o.split()[3]
当我运行
/te.py
时,bash给我一个错误:

-bash: ./te.py: /usr/bin/python^M: bad interpreter: No such file or directory
有什么问题吗?

试试这个:

#!/usr/bin/env python

^M
表示您的行尾有问题您使用的是哪一版本的Python?它可能是
#/usr/bin/python3
如果您使用的是Python 3.xPython 2,因为打印内容周围没有括号。请尝试在vi或vim(创建新的行尾)中编辑您的行。我使用nano编辑此脚本……这并不能解决行尾问题。如果OP以前有行尾问题,那么这个版本很可能会有行尾问题。