2

I'm trying to install pip via

sudo -H python -m pip install -U pip

but this results in the following error.

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 163, in _run_module_as_main
    mod_name, _Error)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 111, in _get_module_details
    __import__(mod_name)  # Do not catch exceptions initializing package
  File "/Library/Python/2.7/site-packages/pip-21.1.2-py2.7.egg/pip/__init__.py", line 1, in <module>
    from typing import List, Optional
ImportError: No module named typing
chairsarecool
  • 41
  • 2
  • 5
  • Don’t, don’t, don’t. 1) Python 2 is end-of-life 2) Install Python from https://www.python.org/downloads/ if you _have_ to (exceedingly bad idea). – xrisk May 25 '21 at 05:44
  • You need to downgrade pip for your Python. See https://stackoverflow.com/a/65871131/7976758/ . Your problem is different but the process of downgrading and URLs are the same. – phd May 25 '21 at 06:19

1 Answers1

12

According to phd's solution

The later versions require Python 3.6+. The syntax f"" is supported by Python 3.6+.

To install pip for Python 2.7 install it from https://bootstrap.pypa.io/pip/2.7/ :

- curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
- python get-pip.py
- python -m pip install --upgrade "pip < 21.0"

The last command is to upgrade to the latest supported version. For Python 2.7 the latest supported is currently pip 20.3.4.

For Python 3.4 install from https://bootstrap.pypa.io/pip/3.4/ . For Python 3.5 — https://bootstrap.pypa.io/pip/3.5/ .

For Python 3.4 the upgrade command is

- python -m pip install --upgrade "pip < 21.1.2"
Talita
  • 190
  • 7