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

Brian Lenihan brian_l@mac.com
Mon, 14 Apr 2003 00:08:54 -0700


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

> On 4/13/03 10:42 PM, "Brian Lenihan" <brian_l@mac.com> wrote:
>
>> 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.
>
>
>>>> import importSys
> /usr
> ['', '/Users/berkowit/Library/Scripts/Python', '/Users/berkowit',
> '/usr/lib/python2.2', '/usr/lib/python2.2/plat-darwin',
> '/usr/lib/python2.2/lib-tk', '/usr/lib/python2.2/lib-dynload',
> '/usr/lib/python2.2/site-packages']
>
> It looks right to me, aside maybe from the very first ' ' in the list. 
> What
> does that mean?

I don't know.  It's been normal behavior since the first time I noticed 
it.
One of the core developers might know.

>  The second path is where I'm saving my .py files, including
> this one. As you can see it will import with just the name, but it 
> won't
> run, even when I add a shebang (#!/usr/bin/env python) at the top and 
> make
> it executable.

I wasn't very articulate, but you figured out what I meant.  Good.
>
> [250-166:~] berkowit% python importSys.py
> python: can't open file 'importSys.py'

Unless you add "dot" to your default path this won't work unless you
do python ./ImportSys.py

> [250-166:~] berkowit% importSys.py
> importSys.py: Command not found.

Same here.  ./importSys.py

The output below won't be relevant (in the context I'm looking for) 
until
you can run the script without specifying what should run it or where 
it is.

>
>
> But:
>
> [250-166:~] berkowit% python ~/Library/Scripts/Python/importSys.py
> /usr
> ['/Users/berkowit/Library/Scripts/Python',
> '/Users/berkowit/Library/Scripts/Python', '/Users/berkowit',
> '/usr/lib/python2.2', '/usr/lib/python2.2/plat-darwin',
> '/usr/lib/python2.2/lib-tk', '/usr/lib/python2.2/lib-dynload',
> '/usr/lib/python2.2/site-packages']

[deleted other following output]