summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2016-09-17 19:54:06 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2016-09-17 19:54:06 (GMT)
commited51b268580c1100b46bf5dbc4b4201146019644 (patch)
treeae52e3f469b71aa5e9634502eedf3c4e50c9f141 /Doc
parent313523ce2dd67db67b7dcbcc5f6d6ca95922b34b (diff)
downloadcpython-ed51b268580c1100b46bf5dbc4b4201146019644.zip
cpython-ed51b268580c1100b46bf5dbc4b4201146019644.tar.gz
cpython-ed51b268580c1100b46bf5dbc4b4201146019644.tar.bz2
Issue #28137: Renames Windows path file to ._pth
Issue #28138: Windows ._pth file should allow import site
Diffstat (limited to 'Doc')
-rw-r--r--Doc/using/windows.rst32
-rw-r--r--Doc/whatsnew/3.6.rst2
2 files changed, 22 insertions, 12 deletions
diff --git a/Doc/using/windows.rst b/Doc/using/windows.rst
index 5c2d864..12bdd9d 100644
--- a/Doc/using/windows.rst
+++ b/Doc/using/windows.rst
@@ -720,15 +720,24 @@ installation directory. So, if you had installed Python to
:file:`C:\\Python\\Lib\\` and third-party modules should be stored in
:file:`C:\\Python\\Lib\\site-packages\\`.
-To completely override :data:`sys.path`, create a text file named ``'sys.path'``
-containing a list of paths alongside the Python executable. This will ignore all
-registry settings and environment variables, enable isolated mode, disable
-importing :mod:`site`, and fill :data:`sys.path` with exactly the paths listed
-in the file. Paths may be absolute or relative to the directory containing the
-file.
+To completely override :data:`sys.path`, create a ``._pth`` file with the same
+name as the DLL (``python36._pth``) or the executable (``python._pth``) and
+specify one line for each path to add to :data:`sys.path`. The file based on the
+DLL name overrides the one based on the executable, which allows paths to be
+restricted for any program loading the runtime if desired.
-When the ``'sys.path'`` file is missing, this is how :data:`sys.path` is
-populated on Windows:
+When the file exists, all registry and environment variables are ignored,
+isolated mode is enabled, and :mod:`site` is not imported unless one line in the
+file specifies ``import site``. Blank paths and lines starting with ``#`` are
+ignored. Each path may be absolute or relative to the location of the file.
+Import statements other than to ``site`` are not permitted, and arbitrary code
+cannot be specified.
+
+Note that ``.pth`` files (without leading underscore) will be processed normally
+by the :mod:`site` module.
+
+When no ``._pth`` file is found, this is how :data:`sys.path` is populated on
+Windows:
* An empty entry is added at the start, which corresponds to the current
directory.
@@ -782,9 +791,10 @@ The end result of all this is:
For those who want to bundle Python into their application or distribution, the
following advice will prevent conflicts with other installations:
-* Include a ``sys.path`` file alongside your executable containing the
- directories to include. This will ignore user site-packages and other paths
- listed in the registry or in environment variables.
+* Include a ``._pth`` file alongside your executable containing the
+ directories to include. This will ignore paths listed in the registry and
+ environment variables, and also ignore :mod:`site` unless ``import site`` is
+ listed.
* If you are loading :file:`python3.dll` or :file:`python36.dll` in your own
executable, explicitly call :c:func:`Py_SetPath` or (at least)
diff --git a/Doc/whatsnew/3.6.rst b/Doc/whatsnew/3.6.rst
index 941a5eb..cabff60 100644
--- a/Doc/whatsnew/3.6.rst
+++ b/Doc/whatsnew/3.6.rst
@@ -108,7 +108,7 @@ Windows improvements:
which means that when the 260 character path limit may no longer apply.
See :ref:`removing the MAX_PATH limitation <max-path>` for details.
-* A ``sys.path`` file can be added to force isolated mode and fully specify
+* A ``._pth`` file can be added to force isolated mode and fully specify
all search paths to avoid registry and environment lookup. See
:ref:`the documentation <finding_modules>` for more information.