directly executing a python script in Unix

Fernando Pérez fperez528 at yahoo.com
Mon Feb 4 08:19:19 EST 2002


Marc Laymon 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.)


$ chmod +x myscript.py

It's not the shebang failing, it's that your script isn't executable (most 
likely). To be safer, use

#!/usr/bin/env python

This will look for python in all your path, and will find it even if it's not 
located in /usr/bin for whatever reason.

cheers,

f.



More information about the Python-list mailing list