pkg_resources.DistributionNotFound: The 'pip==19.1.1' distribution was not found and is required by the application

刘超 1年前 ⋅ 5506 阅读   编辑

一、描述

  1、情况一:在mac上执行pip install requests报如下错误

 

  情况二、在安装mysqlclient时也遇到这个问题,如下

jiangxinyideAir:~ jiangxinyi2$ sudo pip3 install mysqlclient
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 574, in _build_master
    ws.require(__requires__)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 892, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 783, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 19.3.1 (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages), Requirement.parse('pip==19.1.1'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3088, in <module>
    @_call_aside
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3072, in _call_aside
    f(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3101, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 576, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 589, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 778, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==19.1.1' distribution was not found and is required by the application

二、分析

  情况一:
  1、使用pip3安装不再报错(pip3 install requests)

  情况二:

  1、在安装mysqlclient时遇到这个问题,但是pip3安装还是报错

  2、从错误信息,我们知道/usr/local/bin/pip3或/usr/local/bin/pip有问题,这里将pip==19.1.1改为pip>=19.1.1,如下

# 修改之前
#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==19.1.1','console_scripts','pip3'
__requires__ = 'pip==19.1.1'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('pip==19.1.1', 'console_scripts', 'pip3')()
    )

# 修改之后
#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==19.1.1','console_scripts','pip3'
__requires__ = 'pip>=19.1.1'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('pip>=19.1.1', 'console_scripts', 'pip3')()
    )

  3、再次执行pip install --upgrade pip或pip3 install --upgrade pip即可

三、解决方法

  将pip==19.1.1改为pip>=19.1.1,然后再执行pip install --upgrade pip或pip3 install --upgrade pip即可

四、参考文章
1、https://blog.csdn.net/u014259820/article/details/92001684


注意:本文归作者所有,未经作者允许,不得转载

全部评论: 0

    我有话说: