[Tutor] Making Python Find Modules

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Sun, 18 Mar 2001 05:15:49 -0800 (PST)


On Sat, 17 Mar 2001, Britt Green wrote:

> I know that the answer to this question must be painfully obvious, but I 
> can't seem to find it anywhere. If I have a folder called Code in my Python 
> directory, how can I make Python see the modules that are in there? This is 
> on a WinNT box.

One other thing you might need besides PYTHONPATH, if you have
subdirectories in your Code directory, is an '__init__.py' file.  Let's
say that we have the following directory structure:


    /Code/

         Math/
         SecretPlans/

Even if we add Code to your PYTHONPATH, Python will not automatically look
at directories within Code; I'm not quite sure why, but that's the default
behavior.  To fix this, all we need is to put an __init__.py file within
both the /Code/Math and /Code/SecretPlans directories.  __init__.py can
even be an empty file, but as long as it exists, it marks a subdirectory
as prime material for module stuff.

    http://python.org/doc/current/tut/node8.html

covers a lot of the details about modules, so you might want to read this
when you get the chance.


Good luck to you.