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/[email protected]/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
/usr/local
folder is owned byroot
. You aren't allowed to change it. As a rule, I tend to install most packages withsudo
, just so they're available everywhere.pip
under/usr/local/opt
in the first place? That's the only thing that should be upgradingpip
. If you want a more up-to-date version without touching/usr/local/opt
, create a virtual environment first.pip
is not part of the standard Python distribution; it's a 3rd-party tool that some particular distribution installed along with Python.pip
a package in your package manager? If so, upgradepip
using the package manager. (The upgrade might not be available right away through that channel, though. Alternatively, uninstall that and installpip
usingpython -m ensurepip