Skip to content

Commit 201d251

Browse files
authored
DOC: clarify and expand documentation about PYTHONUSERBASE and PYTHONNOUSERSITE (#144637)
1 parent b611db4 commit 201d251

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

Doc/library/site.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ When running under a :ref:`virtual environment <sys-path-init-virtual-environmen
6464
the ``pyvenv.cfg`` file in :data:`sys.prefix` is checked for site-specific
6565
configurations. If the ``include-system-site-packages`` key exists and is set to
6666
``true`` (case-insensitive), the system-level prefixes will be searched for
67-
site-packages, otherwise they won't.
67+
site-packages, otherwise they won't. If the system-level prefixes are not searched then
68+
the user site prefixes are also implicitly not searched for site-packages.
6869

6970
.. index::
7071
single: # (hash); comment

Doc/library/sys_path_init.rst

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ otherwise they are set to the same value as :data:`sys.base_prefix` and
5757
:data:`sys.base_exec_prefix`, respectively.
5858
This is used by :ref:`sys-path-init-virtual-environments`.
5959

60-
Finally, the :mod:`site` module is processed and :file:`site-packages` directories
61-
are added to the module search path. A common way to customize the search path is
62-
to create :mod:`sitecustomize` or :mod:`usercustomize` modules as described in
63-
the :mod:`site` module documentation.
60+
Finally, the :mod:`site` module is processed and :file:`site-packages`
61+
directories are added to the module search path. The :envvar:`PYTHONUSERBASE`
62+
environment variable controls where is searched for user site-packages and the
63+
:envvar:`PYTHONNOUSERSITE` environment variable prevents searching for user
64+
site-packages all together. A common way to customize the search path is to
65+
create :mod:`sitecustomize` or :mod:`usercustomize` modules as described in the
66+
:mod:`site` module documentation.
6467

6568
.. note::
6669

67-
Certain command line options may further affect path calculations.
68-
See :option:`-E`, :option:`-I`, :option:`-s` and :option:`-S` for further details.
70+
The command line options :option:`-E`, :option:`-P`, :option:`-I`,
71+
:option:`-S` and :option:`-s` further affect path calculations, see their
72+
documentation for details.
6973

7074
.. versionchanged:: 3.14
7175

@@ -96,11 +100,10 @@ Please refer to :mod:`site`'s
96100

97101
.. note::
98102

99-
There are other ways how "virtual environments" could be implemented, this
100-
documentation refers implementations based on the ``pyvenv.cfg`` mechanism,
101-
such as :mod:`venv`. Most virtual environment implementations follow the
102-
model set by :mod:`venv`, but there may be exotic implementations that
103-
diverge from it.
103+
There are other ways "virtual environments" could be implemented.
104+
This documentation refers to implementations based on the ``pyvenv.cfg``
105+
mechanism, such as :mod:`venv`, that many virtual environment implementations
106+
follow.
104107

105108
_pth files
106109
----------

Doc/using/cmdline.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,9 @@ conflict.
949949

950950
.. envvar:: PYTHONNOUSERSITE
951951

952-
If this is set, Python won't add the :data:`user site-packages directory
953-
<site.USER_SITE>` to :data:`sys.path`.
952+
This is equivalent to the :option:`-s` option. If this is set, Python won't
953+
add the :data:`user site-packages directory <site.USER_SITE>` to
954+
:data:`sys.path`.
954955

955956
.. seealso::
956957

@@ -964,6 +965,9 @@ conflict.
964965
and :ref:`installation paths <sysconfig-user-scheme>` for
965966
``python -m pip install --user``.
966967

968+
To disable the user site-packages, see :envvar:`PYTHONNOUSERSITE` or the :option:`-s`
969+
option.
970+
967971
.. seealso::
968972

969973
:pep:`370` -- Per user site-packages directory

Lib/site.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
it is also checked for site-packages (sys.base_prefix and
1919
sys.base_exec_prefix will always be the "real" prefixes of the Python
2020
installation). If "pyvenv.cfg" (a bootstrap configuration file) contains
21-
the key "include-system-site-packages" set to anything other than "false"
21+
the key "include-system-site-packages" is set to "true"
2222
(case-insensitive), the system-level prefixes will still also be
23-
searched for site-packages; otherwise they won't.
23+
searched for site-packages; otherwise they won't. If the system-level
24+
prefixes are not included then the user site prefixes are also implicitly
25+
not searched for site-packages.
2426
2527
All of the resulting site-specific directories, if they exist, are
2628
appended to sys.path, and also inspected for path configuration

0 commit comments

Comments
 (0)