[Pythonmac-SIG] Running Python scripts without full paths

Paul Berkowitz berkowit@silcom.com
Fri, 29 Nov 2002 19:49:25 -0800


Hello. I'm brand new to Python, in OS 10.2.2, but an experienced
AppleScripter. (I'm quite amazed by the similarities of the syntax of the
two languages, which is making it easy to learn Python. I predict there will
be a lot of new converts.) I hope you don't mind a newbie setup question.
I'm brand new to Unix as well, and that's probably where I'm going wrong.

I was directed to pythonmac-sig when I was trying to find out how to import
a module with the Interactive interpreter. I saw a reference to Russell
Owen's webpage in the archives, where I found the solution to the problem
(which is Mac OS X-only): making my own 'environment.plist' XML file in
~/.MacOSX. The website URL is

    http://www.astro.washington.edu/owen/AquaEnvVar.html

This should be added to the Python FAQ.

Now I'm stumped again. Russell's solution works for importing modules from
directories that I've added to PYTHONPATH. But I can't get the shell to run
script files without the file's full path or having to cd to the file's
directory first, even though I've now added the directory to the path shell
variable, which in turn has automatically added it to the PATH environment.
I can import the script as a module with only the module name in the
Interactive interpreter:

>>> import module1
Hello module world!


This (very simple) script does run when I give its full or relative path
name or cd to its directory first, in the shell:

[250-166:~] berkowit% python Library/Scripts/Python/module1.py
Hello module world!



But it won't work like this:

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


The shell does know about its directory now (I set path to include it):

[250-166:~] berkowit% printenv 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/Script
s/Python:.

That next-to-last directory:

    /Users/berkowit/Library/Scripts/Python

is the one with module1.py.  Why doesn't the shell find it? Or why doesn't
Python find it since it too knows where it is now, as the module import
makes clear?

Is this another Mac-only problem? Maybe I need to add another key to the
environment.plist file? Or am I just doing something wrong?

Many thanks for any guidance.


-- 
Paul Berkowitz