'pip upgrade uninstalled itself

I used pip today for the first time in a while and I got the helpful message

You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.

So, I went ahead and

pip install --upgrade pip

but things did not go according to plan...

Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 510kB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Uninstalling pip-8.1.1:
Exception:
Traceback (most recent call last):
  File "//anaconda/lib/python2.7/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "//anaconda/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "//anaconda/lib/python2.7/site-packages/pip/req/req_set.py", line 726, in install
    requirement.uninstall(auto_confirm=True)
  File "//anaconda/lib/python2.7/site-packages/pip/req/req_install.py", line 746, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "//anaconda/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "//anaconda/lib/python2.7/site-packages/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "//anaconda/lib/python2.7/shutil.py", line 303, in move
    os.unlink(src)
OSError: [Errno 13] Permission denied: '/anaconda/lib/python2.7/site-packages/pip-8.1.1.dist-info/DESCRIPTION.rst'
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

And now it seems that pip is completely gone from my computer:

$ pip
-bash: //anaconda/bin/pip: No such file or directory

Is pip really gone, that is, did it really uninstall and then fail to reinstall, or did something just get unlinked? How can I avoid this issue in the future? Because I can imagine I will need to upgrade pip again at some point...



Solution 1:[1]

Python comes with a module for installing pip without needing to pull anything from the internet called ensurepip. It's pretty straightforward to use, just run the following in a terminal:

python -m ensurepip

From there you can upgrade pip to the latest the standard way. Additional documentation is available here https://docs.python.org/3/library/ensurepip.html.

Solution 2:[2]

You can reinstall pip with conda:

conda install pip

Looks like you need to have root rights:

sudo conda install pip

Solution 3:[3]

You can use curl to reinstall pip via the Python Packaging Authority website:

curl https://bootstrap.pypa.io/get-pip.py | python

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pikamander2
Solution 2 Mike Müller
Solution 3 Pikamander2