[Tutor] Where does python look for import files

Erik Price erikprice@mac.com
Fri, 19 Apr 2002 22:59:41 -0400


On Friday, April 19, 2002, at 09:54  PM, <ncoulter@es.com> wrote:

> I apologize if this is documented in some obvious place, but I have 
> spent all day looking for this information, and have yet to find it:
>
> What procedure/variables does python use to search for files in import 
> commands?  I see that sys.path contains a list of paths, but am not 
> sure how to modify it.  My goal right now is to set up a folder 
> (c:\python22\scripts) where I can create a folder tree python will 
> search when it encounters an import command.
>
> This is my approach to installing third-party scripts.  Maybe that's 
> not the way to do it.
>
> Would somebody mind pointing me to some info on how best to organize 
> python files in the windows file system?

I really don't know much about Windows, but in Unix you should have an 
environment variable called PYTHONPATH.  Perhaps the same is true of 
Windows.

PYTHONPATH defines the directories searched when importing a module 
using the import statement.

One of the directories in PYTHONPATH is . so you should be able to 
import any modules that are in the current working directory from whence 
you called Python (or the script if it is standalone).

Although everything I've described applies to Unix, I would be surprised 
if it was very different in Windows -- somewhere there should be a 
script which sets the PYTHONPATH environment variable when you launch 
Python, just modify this script.

Hopefully?


Erik