简体   繁体   English

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

[英]Adding a shebang causes No such file or directory error when running my python script

I'm trying to run a python script. 我正在尝试运行python脚本。 It works fine when I run it: 它运行时它工作正常:

python2.5 myscript.py inpt0

The problem starts when I add a shebang: 当我添加一个shebang时,问题就出现了:

#!/usr/bin/env python2.5

Result in: 造成:

$ myscript.py inpt0
: No such file or directory

Try 2: 试试2:

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

Result in: 造成:

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

When I run them directly in the terminal they both work just fine: 当我直接在终端中运行它们时,它们都工作得很好:

$ /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.
>>>

Any hints on how to make this work with shebang? 有关如何使用shebang工作的任何提示?

I had similar problems and it turned out to be problem with line-endings. 我遇到了类似的问题,结果证明是行结尾的问题。 You use windows/linux/mac line endings? 你使用windows / linux / mac line结尾?

Edit: forgot the script name, but as OP says, it's dos2unix <filename> 编辑:忘记了脚本名称,但正如OP所说,它是dos2unix <filename>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM