添加shebang会导致运行我的python脚本时出现此类文件或目录错误

时间:2009-02-10 07:43:52

标签: python shell

我正在尝试运行python脚本。它运行时它工作正常:

python2.5 myscript.py inpt0

当我添加一个shebang时问题就开始了:

#!/usr/bin/env python2.5

结果:

$ myscript.py inpt0
: No such file or directory

尝试2:

#!/usr/local/bin/python2.5

结果:

$ myscript.py inpt0
: bad interpreter: No such file or directoryon2.5

当我直接在终端中运行它们时,它们都可以正常工作:

$ /usr/local/bin/python2.5
Python 2.5.4 (r254:67916, Feb  9 2009, 12:50:32)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

$ /usr/bin/env python2.5
Python 2.5.4 (r254:67916, Feb  9 2009, 12:50:32)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

有关如何使用shebang工作的任何提示?

1 个答案:

答案 0 :(得分:60)

我遇到过类似的问题,但结果却出现问题。你使用windows / linux / mac line endings?

编辑:忘记了脚本名称,但正如OP所说,它是dos2unix <filename>