diff --git a/news/10565.bugfix.rst b/news/10565.bugfix.rst new file mode 100644 index 00000000000..2f0141ffd85 --- /dev/null +++ b/news/10565.bugfix.rst @@ -0,0 +1 @@ +Tweak running-as-root detection, to check ``os.getuid`` if it exists, on Unix-y and non-Linux/non-MacOS machines. diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index c224bd276e2..dbd15cbce63 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -173,9 +173,10 @@ def warn_if_run_as_root() -> None: # checks: https://mypy.readthedocs.io/en/stable/common_issues.html if sys.platform == "win32" or sys.platform == "cygwin": return - if sys.platform == "darwin" or sys.platform == "linux": - if os.getuid() != 0: - return + + if os.getuid() != 0: + return + logger.warning( "Running pip as the 'root' user can result in broken permissions and " "conflicting behaviour with the system package manager. "