[Python] Pip doesn't require root user to install but requires root user to upgrade

Discussão em 'Python' iniciado por Stack, Maio 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm confused by the intended pip usage. Pip comes installed with Python, which is great, but I get the following warnings when new versions come out:

    WARNING: You are using pip version 21.1.1; however, version 21.1.3 is available.
    You should consider upgrading via the '/usr/local/opt/python@3.8/bin/python3.8 -m pip install --upgrade pip' command.


    I follow the instructions to install it using the command they gave. But then it uninstalls my existing pip and is not able to install the new version.

    Installing collected packages: pip
    Attempting uninstall: pip
    Found existing installation: pip 21.1.1
    Uninstalling pip-21.1.1:
    ERROR: Could not install packages due to an OSError: Cannot move the non-empty directory '/usr/local/lib/python3.8/site-packages/pip-21.1.1.dist-info/': Lacking write permission to '/usr/local/lib/python3.8/site-packages/pip-21.1.1.dist-info/'.


    The pip command is now unrecognized, and the official documentation for upgrading pip suggests running:

    python -m pip install -U pip


    which gives the same permission error.

    I Google this error, and found that the community highly advises to not sudo from these questions (this and this). They also advised pip3 install --upgrade pip --user which also gave the same error. The common consensus is to only install pip packages inside virtual environments, but I'm hesitant to have pip completely uninstalled.

    So I got pip to install using sudo, but it's unclear whether I've inadvertently affected (or will affect future) system-wide installations, or how I'd check for these.

    I don't understand why installing pip inside /usr/local/ requires sudo, and whether I should only be using pip exclusively inside virtual environments and never outside it

    Continue reading...

Compartilhe esta Página