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

Brian Lenihan brian_l@mac.com
Sun, 13 Apr 2003 22:42:56 -0700


On Sunday, April 13, 2003, at 05:24 PM, Paul Berkowitz wrote:

> On 4/13/03 3:00 PM, I wrote:
>
>> But now I'm back to an earlier issue. I remembered that I had once 
>> found a
>> way to run files from the Terminal by using 'python filename' without
>> needing to specify the full path, as long as the directory was 
>> included in
>> PYTHONPATH. But I can't do this any more. I have made an 
>> 'environment.plist'
>> file in an invisible ~/.MacOSX/ directory according to Russell Owen's 
>> recipe
>> at <http://www.astro.washington.edu/owen/AquaEnvVar.html>. (I worried 
>> about
>> Mac line endings there myself, but they are indeed Unix line-endings. 
>> Both
>> cat in the Terminal and the Property List Editor see the separate 
>> lines.) I
>> also have a setenv PATH in ~/Library/init/tcsh/path. No joy. I wonder 
>> what
>> I've got wrong this time.
>
>
> Well, I've discovered that Python can _import_ my own modules from that
> specified directory no matter where my current directory is, with just 
> the
> module name, no file paths. So undoubtedly that's what at least one of 
> those
> files  is actually meant to accomplish. If I just give Python the file 
> name
> (without full path) to run it, Python says it can't open the file, but 
> it
> can import it fine in the interactive interpreter without the path.

What happens if you add this to the top of a file in a dir you added to 
your
PYTHONPATH?

import sys
print sys.exec_prefix
print sys.path

Are the results what you expect, or is some other version of python 
trying to run your file?
I ran into a strange problem recently.  One that I will elaborate if 
you are surprised by the
results of the test, above.