Can't find user module despite setting PYTHONPATH

Paul Berkowitz berkowit at silcom.com
Fri Nov 29 14:46:55 EST 2002


I apologize if this is a standard dummy newbie question. So far I haven't
come upon the answer here.

I'm beginning Python, but this is not my first scripting language. Having
read the excellent online tutorial, I'm now working my way through the also
excellent "Learning Python" published by O'Reilly. I'm using Mac OS 10.2.2
which comes with Python 2.2. My shell in the Terminal app is tcsh. (I'm
brand new to Unix altogether, like other Mac users who have switched to OS
X.)

OK. None of my books explains exactly how to set PYTHONPATH in tcsh, but I
think I've worked it out. I want to include the pre-packaged modules, which
mostly seem to be in /usr/lib/python2.2/, and my own directory where I store
Python files and modules, ~/Library/Scripts/Python/. So I did this in tcsh:

setenv PYTHONPATH 
.:/usr/lib/python2.2/:/Users/berkowit/Library/Scripts/Python/:/usr/lib/pytho
n2.2/plat-darwin/ # all one line


It worked, and printenv PYTHONPATH  echoes the same thing back.

I quit and relaunched the Python Interactive interpreter, and now I no
longer get a SyntaxError when I call a simple module I saved in my
~/Library/Scripts/Python/ directory. Instead I get: an ImportError:

>>> import module1.py
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named module1.py


But that's not true. It's there - I can see it. I purposely haven't prefixed
a shebang line to the file, because I'm trying to see how it imports
modules, not runs scripts. Do I need to? The file script is simply:

print 'Hello module world!'

What am I doing wrong?





-- 
Paul Berkowitz




More information about the Python-list mailing list