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

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


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? 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.

[250-166:~] berkowit% python importSys.py
python: can't open file 'importSys.py'

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


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']


and:

[250-166:~] berkowit% ./Library/Scripts/Python/importSys.py
/usr
['./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']


These two don't have that ' 'at the beginning.



-- 
Paul Berkowitz