python3解决pip升级到10.0.1之后会遇到的错误:module 'pip' has no attribute 'main'

错误:module 'pip' has no attribute 'main'

pip升级到10.0.1之后可能会出现这个错误。

环境:
pip version : 10.0.1
python version : 3.6.4
mac os : 10.12.6 

错误出现路径还原:

升级pip
$python -m pip install pip --upgrade
Requirement already up-to-date: pip in /usr/local/lib/python3.6/site-packages (10.0.1)

升级后使用pip,报错
$pip -V
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2332, in resolve
    return functools.reduce(getattr, self.attrs, module)
AttributeError: module 'pip' has no attribute 'main'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/python/libexec/bin/pip", line 11, in 
    load_entry_point('pip==9.0.3', 'console_scripts', 'pip3')()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
    return ep.load()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2334, in resolve
    raise ImportError(str(exc))
ImportError: module 'pip' has no attribute 'main'

解决方法:

  • 方法一(未测试)
    网上有类似的错误描述:stackoverflow这里
    里边提到降级处理:
python3 -m pip install --user --upgrade pip==9.0.3

没有亲测这种方式,应该是可以的。

  • 方法二(已测试,有效)
    更新pip
$curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$python get-pip.py

其中,如果是python3对应的pip3,则需要使用python3,如下:

$python3 get-pip.py

更新完毕,便可使用pip或者pip3

$pip -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
$pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
  • 方法三(未测试)
    网上有说重新安装python3即可解决,这里,未测试。
brew reinstall python3

更多博客,请关注
https://blog.csdn.net/rflyee/
https://www.jianshu.com/u/ff8bcd76e5a7

你可能感兴趣的:(python3解决pip升级到10.0.1之后会遇到的错误:module 'pip' has no attribute 'main')