Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

shell - Adding a shebang causes No such file or directory error when running my python script

I'm trying to run a python script. It works fine when I run it:

python2.5 myscript.py inpt0

The problem starts when I add a shebang:

#!/usr/bin/env python2.5

Result in:

$ myscript.py inpt0
: No such file or directory

Try 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had similar problems and it turned out to be problem with line-endings. You use windows/linux/mac line endings?

Edit: forgot the script name, but as OP says, it's dos2unix <filename>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...