diff -r ebf522ef3b5a -r 77022e502321 Doc/using/windows.rst --- a/Doc/using/windows.rst Thu Sep 23 11:09:15 2010 +0200 +++ b/Doc/using/windows.rst Fri Sep 24 23:59:40 2010 +0900 @@ -174,6 +174,53 @@ :program:`regedit` (start it by typing "regedit" into :menuselection:`Start --> Run`). +How sys.path is formed +^^^^^^^^^^^^^^^^^^^^^^ +This section describes the functionality, not the implementation (ie, the order +in which these are actually fetched is different) + + * An empty entry is added at the start, which corresponds + to the current directory. + + * If the :envvar:`PYTHONPATH` exists, its entries are added next. + + * If registry for `Application Paths` - that is, sub-keys + under the main PythonPath registry key - exists, These are added next (the + order of sub-key processing is undefined). HKEY_CURRENT_USER is searched and + added first. HKEY_LOCAL_MACHINE is searched and added next. (Note that all + known installers only use HKLM, so HKCU is typically empty) + + * If the :envvar:`PYTHONHOME` is set, we believe it as `Python Home`. + Otherwise, We regards path of our host .EXE as `Python Home` and + locate our `landmark` (:file:`lib\\os.py`) and deduce our home. + + - If we DO have a `Python Home`: The relevant sub-directories (Lib, plat-win, + etc) are based on the `Python Home` + - If we DO NOT have a `Python Home`, the core Python Path is loaded from the + registry. This is the main PythonPath key, and both HKLM and HKCU are + combined to form the path + + * If we cann't locate the Python Home, have not had a :envvar:`PYTHONPATH` + specified, and can't locate any Registry entries (ie, we have _nothing_ + we can assume is a good path), a default path with relative entries is + used (eg. :file:`.\Lib;.\plat-win`, etc) + +The end result of all this is: + + * When running :file:`python.exe`, or any other .exe in the main Python directory + (either an installed version, or directly from the PCbuild directory), + the core path is deduced, and the core paths in the registry are + ignored. Other `Application Paths` in the registry are always read. + + * When Python is hosted in another exe (different directory, embedded via + COM, etc), the Python Home will not be deduced, so the core path from + the registry is used. Other `Application Paths` in the registry are + always read. + + * If Python can't find its home and there is no registry (eg, frozen + exe, some very strange installation setup) you get a path with + some default, but relative, paths. + Executing scripts -----------------