Skip to content

ensurepip warning about running pip as the root user cannot be suppressed #139363

@zvickery

Description

@zvickery

Bug report

Bug description:

The Github Action for installing python currently invokes ensurepip before installing pip. This all works great. It even sets PIP_ROOT_USER_ACTION=ignore to suppress the warning about root (text below), which is common when using containerized environments in CI. However it seems that pip respects this environment variable while ensurepip does not. In particular, https://github.com/python/cpython/blob/main/Lib/ensurepip/__init__.py#L101 seems to guarantee that ensurepip will honor neither environment variables nor the pip configuration file for controlling this.

I have a few questions about this and didn't see a prior ticket, so here goes:

  • Is the Github action taking the correct approach to install Python? (AFAICT, yes)
  • Is ensurepip ignoring all environment and configuration correct? AFAICT this was added a long time ago to address some test suite issues
  • Is there any way I have missed to suppress the below message when the installer invokes ensurepip within a container running as root? WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
  • If there is no way, should there be? IMO, yes. My proposal would be to alter the sanitization to preserve this variable. I'm happy to PR that if it is the best approach here.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-ensurepiptype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions