]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
DOC: clarify and expand documentation about PYTHONUSERBASE and PYTHONNOUSERSITE ...
authorThomas A Caswell <tcaswell@gmail.com>
Mon, 2 Mar 2026 15:54:26 +0000 (10:54 -0500)
committerGitHub <noreply@github.com>
Mon, 2 Mar 2026 15:54:26 +0000 (15:54 +0000)
Doc/library/site.rst
Doc/library/sys_path_init.rst
Doc/using/cmdline.rst
Lib/site.py

index 4686c9fc92ced295020a334a90dfe68fc259534b..04895ae4ec524b33b3e3cf189256eaa4e7fc18c7 100644 (file)
@@ -64,7 +64,8 @@ When running under a :ref:`virtual environment <sys-path-init-virtual-environmen
 the ``pyvenv.cfg`` file in :data:`sys.prefix` is checked for site-specific
 configurations. If the ``include-system-site-packages`` key exists and is set to
 ``true`` (case-insensitive), the system-level prefixes will be searched for
-site-packages, otherwise they won't.
+site-packages, otherwise they won't.  If the system-level prefixes are not searched then
+the user site prefixes are also implicitly not searched for site-packages.
 
 .. index::
    single: # (hash); comment
index a37bb59e7cec760507cf20186e8a37af6165b67b..e6c2cddbe8424875003e42e515d49e6200c3dbb8 100644 (file)
@@ -57,15 +57,19 @@ otherwise they are set to the same value as :data:`sys.base_prefix` and
 :data:`sys.base_exec_prefix`, respectively.
 This is used by :ref:`sys-path-init-virtual-environments`.
 
-Finally, the :mod:`site` module is processed and :file:`site-packages` directories
-are added to the module search path. A common way to customize the search path is
-to create :mod:`sitecustomize` or :mod:`usercustomize` modules as described in
-the :mod:`site` module documentation.
+Finally, the :mod:`site` module is processed and :file:`site-packages`
+directories are added to the module search path.  The :envvar:`PYTHONUSERBASE`
+environment variable controls where is searched for user site-packages and the
+:envvar:`PYTHONNOUSERSITE` environment variable prevents searching for user
+site-packages all together.  A common way to customize the search path is to
+create :mod:`sitecustomize` or :mod:`usercustomize` modules as described in the
+:mod:`site` module documentation.
 
 .. note::
 
-   Certain command line options may further affect path calculations.
-   See :option:`-E`, :option:`-I`, :option:`-s` and :option:`-S` for further details.
+   The command line options :option:`-E`, :option:`-P`, :option:`-I`,
+   :option:`-S` and :option:`-s` further affect path calculations, see their
+   documentation for details.
 
 .. versionchanged:: 3.14
 
@@ -96,11 +100,10 @@ Please refer to :mod:`site`'s
 
 .. note::
 
-   There are other ways how "virtual environments" could be implemented, this
-   documentation refers implementations based on the ``pyvenv.cfg`` mechanism,
-   such as :mod:`venv`. Most virtual environment implementations follow the
-   model set by :mod:`venv`, but there may be exotic implementations that
-   diverge from it.
+   There are other ways "virtual environments" could be implemented.
+   This documentation refers to implementations based on the ``pyvenv.cfg``
+   mechanism, such as :mod:`venv`, that many virtual environment implementations
+   follow.
 
 _pth files
 ----------
index 93df4fcdc630a5050b0e0f40af06a5d016d14bea..f4085ff842aea98d88206fbbbac34e14a6ce7943 100644 (file)
@@ -949,8 +949,9 @@ conflict.
 
 .. envvar:: PYTHONNOUSERSITE
 
-   If this is set, Python won't add the :data:`user site-packages directory
-   <site.USER_SITE>` to :data:`sys.path`.
+   This is equivalent to the :option:`-s` option.  If this is set, Python won't
+   add the :data:`user site-packages directory <site.USER_SITE>` to
+   :data:`sys.path`.
 
    .. seealso::
 
@@ -964,6 +965,9 @@ conflict.
    and :ref:`installation paths <sysconfig-user-scheme>` for
    ``python -m pip install --user``.
 
+   To disable the user site-packages, see :envvar:`PYTHONNOUSERSITE` or the :option:`-s`
+   option.
+
    .. seealso::
 
       :pep:`370` -- Per user site-packages directory
index 1b7a656551b853f3c4708fef696c2790eff3ed7e..5f09a7dd8c91c02918d3cffe004a50f312885c6a 100644 (file)
@@ -18,9 +18,11 @@ sys.prefix and sys.exec_prefix are set to that directory and
 it is also checked for site-packages (sys.base_prefix and
 sys.base_exec_prefix will always be the "real" prefixes of the Python
 installation). If "pyvenv.cfg" (a bootstrap configuration file) contains
-the key "include-system-site-packages" set to anything other than "false"
+the key "include-system-site-packages" is set to  "true"
 (case-insensitive), the system-level prefixes will still also be
-searched for site-packages; otherwise they won't.
+searched for site-packages; otherwise they won't.  If the system-level
+prefixes are not included then the user site prefixes are also implicitly
+not searched for site-packages.
 
 All of the resulting site-specific directories, if they exist, are
 appended to sys.path, and also inspected for path configuration