From: Thomas A Caswell Date: Mon, 2 Mar 2026 15:54:26 +0000 (-0500) Subject: DOC: clarify and expand documentation about PYTHONUSERBASE and PYTHONNOUSERSITE ... X-Git-Tag: v3.15.0a7~107 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=201d251567738c234081329a244449e08fa86245;p=thirdparty%2FPython%2Fcpython.git DOC: clarify and expand documentation about PYTHONUSERBASE and PYTHONNOUSERSITE (#144637) --- diff --git a/Doc/library/site.rst b/Doc/library/site.rst index 4686c9fc92ce..04895ae4ec52 100644 --- a/Doc/library/site.rst +++ b/Doc/library/site.rst @@ -64,7 +64,8 @@ When running under a :ref:`virtual environment ` 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 ` to + :data:`sys.path`. .. seealso:: @@ -964,6 +965,9 @@ conflict. and :ref:`installation paths ` 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 diff --git a/Lib/site.py b/Lib/site.py index 1b7a656551b8..5f09a7dd8c91 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -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