It seems impossible to upgrade pip, even locally, without also breaking the system pip:
$ sudo apt install python3-pip
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
$ python3 -m pip install --user --upgrade pip
$ python3 -m pip --version
pip 19.2.1 from /home/ghawkins/.local/lib/python3.5/site-packages/pip (python 3.5)
$ pip3 --version
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
I've added a comment to this SO answer asking why this is.
It turns out it's infinitely easier to just bootstrap a few things and then do everything else via venv:
$ sudo apt install python3 python3-pip python3-venv
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
$ python3 -m venv env
$ source env/bin/activate
$ pip install --upgrade pip
$ pip --version
pip 19.2.1 from /home/ghawkins/git/gst-absolutetimestamps/env/lib/python3.5/site-packages/pip (python 3.5)
$ pip install --upgrade setuptools wheel
Note that venv, used as above, takes the name given to it, i.e. env in this case, and creates a subdirectory, with that name, in your current directory.
So the intention is that you create such environments on a per-project basis. When you move from one project to another you need to activate the environment for the current project, i.e. use source ... as above.
Any packages that you install, while a particular environment is active, will end up somewhere below the base directory corresponding to that environment.
The last step above, installing setuptools and the more modern wheel, are needed if you later end up installing something that comes as a source archives. If you don't install them, pip will still be able to install most things (pre-built binary archives) and will fail fairly clearly in the situations where the setuptools or wheel package are needed.