Skip to content

Commit e9fed34

Browse files
committed
Don't erroneously emit warning about running pip as root
Check the uid using getuid() on platforms other than Linux and Mac OS before warning about running pip as root. Before this change, pip was emitting this warning even when it was run as a non-root user.
1 parent 9f18a40 commit e9fed34

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

news/10565.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Only warn about running pip as root if it is actually being run as root

src/pip/_internal/cli/req_command.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,14 @@ def warn_if_run_as_root() -> None:
173173
# checks: https://mypy.readthedocs.io/en/stable/common_issues.html
174174
if sys.platform == "win32" or sys.platform == "cygwin":
175175
return
176-
if sys.platform == "darwin" or sys.platform == "linux":
177-
if os.getuid() != 0:
178-
return
179-
logger.warning(
180-
"Running pip as the 'root' user can result in broken permissions and "
181-
"conflicting behaviour with the system package manager. "
182-
"It is recommended to use a virtual environment instead: "
183-
"https://pip.pypa.io/warnings/venv"
184-
)
176+
177+
if os.getuid() == 0:
178+
logger.warning(
179+
"Running pip as the 'root' user can result in broken permissions and "
180+
"conflicting behaviour with the system package manager. "
181+
"It is recommended to use a virtual environment instead: "
182+
"https://pip.pypa.io/warnings/venv"
183+
)
185184

186185

187186
def with_cleanup(func: Any) -> Any:

0 commit comments

Comments
 (0)