简体   繁体   中英

After upgrading pip, it no longer works

I recently updated my Homebrew installation of Python 3.8.2 to 3.8.3. After doing so, I ran

$ pip3 install -U pip

in order to check for any pip updates. It updated my installation of pip from 20.0.2 to 20.1.1, and ever since I ran that command, pip throws an error any time I try to use it. Here's the error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 584, in _build_master
    ws.require(__requires__)
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 901, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 792, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 20.1.1 (/usr/local/lib/python3.8/site-packages), Requirement.parse('pip==20.0.2'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/python@3.8/bin/pip3", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3255, in <module>
    def _initialize_master_working_set():
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3238, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3267, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 586, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 599, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 787, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==20.0.2' distribution was not found and is required by the application

It seems that something went wrong during the upgrade process that failed to change the version check within the code. I saw this similar question , but the accepted answer is not working for me. How can I make pip usable again?

As per Python documentation, the correct way to use pip now would be via the correct Python executable, eg

python3 -m pip install -U pip

I had experienced a similar problem on my Ubuntu and here's how I solved my problem:

  1. First restore the older version by reinstalling it from your OS package manager (You may need to uninstall first).
  2. Upgrade to the latest version for your user (as opposed to installing in a system location) with the following command
pip3 install --user -U pip

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM