search path

Martin von Loewis loewis at informatik.hu-berlin.de
Sat Nov 3 08:32:58 EST 2001


Jive Dadson <jdadson at ix.netcom.com> writes:

> I R'd the FM, but I can't figure it out:  How do I set the search path
> Python uses to find modules?

The search path is always in sys.path. How sys.path is initialized
varies with platform and Python version. If you need the full story,
you best study the Python source code.

> The documentation that came with Python says it uses an enviornment
> variable named PYTHONPATH.  What kind of environment variable?  I'm
> running this under Windows (spit!). 

There are environment variables on Windows, and PYTHONPATH is honored
there, also.

However, on any system, sys.path will include directories even if
PYTHONPATH is not set. On Windows, these directories include:
- directories relative to the Python installation. Those are usually
  retrieved from the registry, since Python, at installation time,
  adds a few registry entries
- directories for other packages that added the registry
- individual paths for modules, also found in the registry.
- directories listed in .pth files on sys.path, if site.py is imported.

Regards,
Martin



More information about the Python-list mailing list