directly executing a python script in Unix

Marc Laymon laymon at crd.ge.com
Tue Feb 5 08:47:47 EST 2002


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 ?

Thanks.

> "Marc Poulin" <mpoulin at verinet.com> wrote in message > news:<3c5ef07d$0$2201$7586b60c at news.frii.com>...
> In article <60018f02.0202041208.67d3100e at posting.google.com>, "Marc
> Laymon" <laymon at crd.ge.com> wrote:
> 
> > I am just learning python.  I have written a few simple scripts which
> > run fine when invoked using "python myscript.py".  The Python manual
> > says you can execute a Python script directly In Unix by making the
> > first line "#!/usr/bin/python", then giving the command "./myscript.py".
> >  However, when I try this, I get an error "Command not found.".  I get
> > the same error under both Linux and Solaris. Using the same format for
> > perl works fine.  Why doesn't the "#!/usr/bin/python" line work for
> > Python ?  (perl and python are both in /usr/bin on my Linux system.)
> > 
> > Thanks.
> > 
> > Marc Laymon
> 
> First, use the "which" command to make sure the interpreter is in your
> path:
> 
>      which python
> 
> You should see
> 
>      /usr/bin/python
> 
> Next, make your script executable. Type
> 
>      chmod +x myscript.py
> 
> at the command line.



More information about the Python-list mailing list