最近由于升级python版本,导致pip不可用,发生下面的错误
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 659, in _build_master
ws.require(__requires__)
File "/usr/local/python3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 967, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/python3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 858, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 18.1 (/home/fantao/.local/lib/python3.6/site-packages), Requirement.parse('pip==18.0'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/python3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3017, in <module>
@_call_aside
File "/usr/local/python3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3003, in _call_aside
f(*args, **kwargs)
File "/usr/local/python3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3030, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/python3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 661, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/local/python3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 674, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/local/python3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 853, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==18.0' distribution was not found and is required by the application
解决方案:
- https://pip.pypa.io/en/stable/installing/ 获取get-pip.py文件
- 执行命令
python get-pip.py pip==18.0 --trusted-host pypi.douban.com --user -U --no-warn-script-location