mirror of https://github.com/python/cpython
Issue #11948: clarify modules search path
This commit is contained in:
parent
972cfb9169
commit
f0229aa51c
|
@ -159,24 +159,22 @@ The Module Search Path
|
||||||
|
|
||||||
.. index:: triple: module; search; path
|
.. index:: triple: module; search; path
|
||||||
|
|
||||||
When a module named :mod:`spam` is imported, the interpreter searches for a
|
When a module named :mod:`spam` is imported, the interpreter first searches for
|
||||||
file named :file:`spam.py` in the directory containing the input script and
|
a built-in module with that name. If not found, it then searches for a file
|
||||||
then in the list of directories specified by the environment variable
|
named :file:`spam.py` in a list of directories given by the variable
|
||||||
:envvar:`PYTHONPATH`. This has the same syntax as the shell variable
|
:data:`sys.path`. :data:`sys.path` is initialized from these locations:
|
||||||
:envvar:`PATH`, that is, a list of directory names. When :envvar:`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
|
|
||||||
:file:`.:/usr/local/lib/python`.
|
|
||||||
|
|
||||||
Actually, modules are searched in the list of directories given by the variable
|
* the directory containing the input script (or the current directory).
|
||||||
``sys.path`` which is initialized from the directory containing the input script
|
* :envvar:`PYTHONPATH` (a list of directory names, with the same syntax as the
|
||||||
(or the current directory), :envvar:`PYTHONPATH` and the installation- dependent
|
shell variable :envvar:`PATH`).
|
||||||
default. This allows Python programs that know what they're doing to modify or
|
* the installation-dependent default.
|
||||||
replace the module search path. Note that because the directory containing the
|
|
||||||
script being run is on the search path, it is important that the script not have
|
After initialization, Python programs can modify :data:`sys.path`. The
|
||||||
the same name as a standard module, or Python will attempt to load the script as
|
directory containing the script being run is placed at the beginning of the
|
||||||
a module when that module is imported. This will generally be an error. See
|
search path, ahead of the standard library path. This means that scripts in that
|
||||||
section :ref:`tut-standardmodules` for more information.
|
directory will be loaded instead of modules of the same name in the library
|
||||||
|
directory. This is an error unless the replacement is intended. See section
|
||||||
|
:ref:`tut-standardmodules` for more information.
|
||||||
|
|
||||||
.. %
|
.. %
|
||||||
Do we need stuff on zip files etc. ? DUBOIS
|
Do we need stuff on zip files etc. ? DUBOIS
|
||||||
|
|
Loading…
Reference in New Issue