directly executing a python script in Unix - RESOLVED !
Marc Laymon
laymon at crd.ge.com
Wed Feb 6 10:08:38 EST 2002
The dreaded DOS CR is the problem ! I initially wrote the script in a
Windows editor, then moved it to Linux. I was not aware the CR's
would
make a difference on the #!line, plus I could not even see them. I
was looking at the file in Emacs, which used to show CR's as ^M. I
recently upgraded to
a new version of Linux and Emacs apparently no longer shows the ^M,
which I was not aware of until I ran the head command you suggested.
This command showed that the file did contain the CR's.
Thanks for your help.
Marc Laymon
Michael Hudson <mwh at python.net> wrote in message news:<uvgdcowgq.fsf at python.net>...
> 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.
More information about the Python-list
mailing list