I updated pip on Ubuntu 14.04 with pip install pip --upgrade and now it's broken, saying it needs Python 3.5 or above, but I have Python 3.4.

What packages do I need to reinstall to fix pip?

$ pip3 search youtube-dl
Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip._internal.cli.main import main
  File "/usr/local/lib/python3.4/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/local/lib/python3.4/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/usr/local/lib/python3.4/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/usr/local/lib/python3.4/dist-packages/pip/_internal/cli/cmdoptions.py", line 28, in <module>
    from pip._internal.models.target_python import TargetPython
  File "/usr/local/lib/python3.4/dist-packages/pip/_internal/models/target_python.py", line 4, in <module>
    from pip._internal.utils.misc import normalize_version_info
  File "/usr/local/lib/python3.4/dist-packages/pip/_internal/utils/misc.py", line 20, in <module>
    from pip._vendor import pkg_resources
  File "/usr/local/lib/python3.4/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 92, in <module>
    raise RuntimeError("Python 3.5 or later is required")
RuntimeError: Python 3.5 or later is required

$ python3 --version
Python 3.4.3
$ python
python                                 python2-jsondiff                       python3.4m-config                      python-mkdebian
python2                                python2-jsonpatch                      python3-config                         pythontex
python2.7                              python3                                python3m                               pythontex3
python2.7-config                       python3.4                              python3m-config                        
python2.7-pyrexc                       python3.4-config                       python-config                          
python2-config                         python3.4m                             python-html-css-webkit-hello-world.py 
$ find /usr -maxdepth 4 -iname pip -type d

Looks like you upgraded pip to a version that doesn't support your Python version.

Uninstall pip and reinstall the system pip:

sudo apt purge python-pip python3-pip
sudo rm -rf /usr/local/lib/python2.7/dist-packages/pip
sudo rm -rf /usr/local/lib/python3.4/dist-packages/pip
sudo apt install python-pip python3-pip

Do not run pip install pip --upgrade

Note that you are using an unsupported version of Ubuntu, an unsupported version of Python (if Python 2) and a nearly unsupported Python (3.4 EOL June 2020). You ought to consider upgrading to a newer LTS. Ubuntu 16.04 would be a step up, 18.04 would be better, or wait for 20.04 next month. They all come with modern Python 3, and since 18.04 don't install Python 2 by default.

  • 4
    Thanks @ben_nuttall Your answer made my brain "ding", I ran specified commands, also these ones: sudo apt-get install --reinstall python3-setuptools python3-wheel python3-pkg-resources; sudo rm -rf /usr/local/bin/pip3; sudo rm -rf /usr/local/bin/pip; sudo rm -rf /usr/local/lib/python3.4/dist-packages/setuptools; sudo rm -rf /usr/local/lib/python3.4/dist-packages/wheel; sudo rm -rf /usr/local/lib/python3.4/dist-packages/pkg_resources and now problem is fixed, pip works again. – superqwerty Mar 18 '20 at 13:18
  • Great! Be sure to select this as the correct answer – ben_nuttall Mar 18 '20 at 20:06
  • how to do the same but for pip in a virtual environment? – Mohammad Ali Jul 27 '20 at 10:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.