directly executing a python script in Unix

Michael Hudson mwh at python.net
Tue Feb 5 09:02:50 EST 2002


laymon at crd.ge.com (Marc Laymon) writes:

> Several people suggested that the script needs to be
> executable.  However, python is in
> /usr/bin/python and the script is executable:
> 
> (laymon) [23] which python
> /usr/bin/python
> (laymon) [24] ls -l retest.py
> -rwxr-xr-x    1 laymon   omtool       1747 Feb  4 10:55 retest.py*
> 
> If the script is not executable, you get a "Permission denied"
> error, not "Command not found"
> 
> (laymon) [25] chmod -x retest.py
> (laymon) [26] ./retest.py
> ./retest.py: Permission denied.
> (laymon) [27] chmod +x retest.py
> (laymon) [28] ./retest.py
> ./retest.py: Command not found.
> (laymon) [29] ls -l retest.py
> -rwxr-xr-x    1 laymon   omtool       1747 Feb  4 10:55 retest.py*
> 
> I can duplicate the error message with a perl script by changing
> "#!/usr/bin/perl" to "#!/usr/bin/foo", so it seems that for some
> reason, Unix can't find python, but since /usr/bin is in my path
> and I am explicitly giving the command "usr/bin/python",
> I can't figure out why.  Anybody have any other ideas ?

Have carriage returns snuck into your script?

try

$ head -n1 retest.py | cat -v

if the result is

#!/usr/bin/python^M

then that's your problem.

Cheers,
M.

-- 
  If a train station is a place where a train stops, what's a
  workstation?                            -- unknown (to me, at least)



More information about the Python-list mailing list