@@ -897,6 +897,92 @@ To install "SomePackage" into an environment with ``site.USER_BASE`` customized
897897 set PYTHONUSERBASE=c:/myappenv
898898 py -m pip install --user SomePackage
899899
900+ Automatic User Install Fallback
901+ -------------------------------
902+
903+ .. important ::
904+
905+ When pip detects that the normal ``site-packages `` directory is not
906+ writeable (e.g., when running as a non-root user on a system Python),
907+ it will **automatically default to a user installation ** without requiring
908+ the ``--user `` flag. You will see this message:
909+
910+ .. code-block :: text
911+
912+ Defaulting to user installation because normal site-packages is not writeable
913+
914+ This automatic fallback can be surprising, especially if the warning is
915+ missed among other output. If you explicitly want to prevent this behavior
916+ and instead receive an error when ``site-packages `` is not writeable, use
917+ the ``--no-user `` option.
918+
919+ The ``--no-user `` Option
920+ ------------------------
921+
922+ The ``--no-user `` option explicitly disables user installs, ensuring that pip
923+ will attempt to install to the system ``site-packages `` directory. If pip
924+ cannot write to ``site-packages ``, it will fail with a permission error rather
925+ than silently falling back to a user install.
926+
927+ .. tab :: Unix/macOS
928+
929+ .. code-block :: shell
930+
931+ python -m pip install --no-user SomePackage
932+
933+ .. tab :: Windows
934+
935+ .. code-block :: shell
936+
937+ py -m pip install --no-user SomePackage
938+
939+ This is useful in scenarios where:
940+
941+ - You want to ensure packages are installed globally and not in user space.
942+ - You want pip to fail loudly if it doesn't have the necessary permissions,
943+ rather than silently succeeding with a user install.
944+ - You are debugging installation issues and want to understand exactly where
945+ packages are being installed.
946+
947+ Environment Variables
948+ ---------------------
949+
950+ The user install behavior can also be controlled via environment variables:
951+
952+ ``PIP_USER ``
953+ Set to ``1 ``, ``true ``, or ``yes `` to enable user installs by default
954+ (equivalent to ``--user ``). Set to ``0 ``, ``false ``, or ``no `` to disable
955+ the automatic user install fallback (equivalent to ``--no-user ``).
956+
957+ .. tab :: Unix/macOS
958+
959+ .. code-block :: shell
960+
961+ # Always use user installs
962+ export PIP_USER=1
963+ python -m pip install SomePackage
964+
965+ # Never fall back to user installs
966+ export PIP_USER=0
967+ python -m pip install SomePackage
968+
969+ .. tab :: Windows
970+
971+ .. code-block :: shell
972+
973+ :: Always use user installs
974+ set PIP_USER=1
975+ py -m pip install SomePackage
976+
977+ :: Never fall back to user installs
978+ set PIP_USER=0
979+ py -m pip install SomePackage
980+
981+ ``PYTHONUSERBASE ``
982+ Customizes the user install location by changing the value of
983+ ``site.USER_BASE ``.
984+
985+
900986``pip install --user `` follows four rules:
901987
902988#. When globally installed packages are on the python path, and they *conflict *
0 commit comments