what is Python's module search path?

Stephen Ferg steve at ferg.org
Thu Jan 8 18:20:00 EST 2004


Thanks.

It says """When a module named spam is imported, the interpreter
searches for a file named spam.py in the current directory, and then
in the list of directories specified by the environment variable
PYTHONPATH. ... When PYTHONPATH is not set, or when the file is not
found there, the search continues in an installation-dependent default
path; on Unix, this is usually .:/usr/local/lib/python.

Actually, modules are searched in the list of directories given by the
variable sys.path which is initialized from the directory containing
the input script (or the current directory), PYTHONPATH and the
installation-dependent default."""

Is the installation-dependent default path on Windows usually
Lib/site-packages?

If so, then it looks like my original search order was wrong, 
and the correct search order (on Windows) is:

---------------------------------------------------------
 * Python's built-in modules, including modules in the standard
library
 * the directory from which your main module was loaded
 * in directories in PYTHONPATH
 * in the /python23/Libs/site-packages directory
--------------------------------------------------------

Is that correct?

Part of what is confusing me is that Lib/site-packages is pretty
poorly documented.



More information about the Python-list mailing list