[Pythonmac-SIG] Can't run Python scripts from Terminal

Paul Berkowitz berkowit@silcom.com
Sun, 13 Apr 2003 12:23:05 -0700


I'm just learning Python, and am very new still to all Unix things in OS X.
I have only the default OS 10.2 installation of Python 2.2.

I can run Python scripts from the Terminal when I start off with 'python
filename.py' but not when I include a "#!' line and just call the filename
from the same working directory, after making the file executable. Can
anyone tell me what might be wrong/

More precisely, I have a perfectly (at last!) formatted Python script which
I can import in the interactive command line. I can also run it perfectly
from the Terminal when I am in its directory as working directory:

    [250-166:~/Library/Scripts/Python] berkowit% python lunch.py


'lunch.py' just runs - everything is correct as it should be.

At the very top of the file, I have:

    #!/usr/bin/env python

and I made the file executable by

    [250-166:~/Library/Scripts/Python] berkowit% chmod +x lunch.py


(confirmed by ls -1).

But when I try:

    [250-166:~/Library/Scripts/Python] berkowit% lunch.py
    lunch.py: Command not found.
    

What's the problem? I'm sure this used to work, the last time I tried it
(which was before a clean reinstall of OS 10.2). It also doesn't work if I
put

    #!/usr/local/bin/python

as the shebang line. Due to some advice here, I do have a
~/Library/init/tcsh/path file with

setenv PATH 
"/Users/berkowit/bin/powerpc-apple-darwin:/Users/berkowit/bin:/usr/local/bin
:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/Users/berkowit/Library/Scrip
ts/Python"


(all one line) in it. but that's just for looking for .py files, if I
remember correctly.

Why is the shell not understanding my shebang line? It's not a great
hardship to write 'python ' every time, but I would like to understand
what's going on.

-- 
Paul Berkowitz