AttributeError: module 'pip' has no attribute 'main'如何解决?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AttributeError: module 'pip' has no attribute 'main'如何解决?相关的知识,希望对你有一定的参考价值。

Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'C:\Users\Administrator\Desktop\pycharmDoc\Pict_Processing\venv\Scripts\python.exe'.

Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\packaging_tool.py", line 192, in main
retcode = do_install(pkgs)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\packaging_tool.py", line 109, in do_install
return pip.main(['install'] + pkgs)
AttributeError: module 'pip' has no attribute 'main'

由于pip 10版本中没有main(),如果在不降级的情况下,修改这个文件

C:\\Program Files\\JetBrains\\PyCharm Community Edition 2017.3.3\\helpers\\packaging_tool.py

在头部加上

import pip._internal as pip_new

然后分别修改文件中的这两行中的pip

return pip.main(['install'] + pkgs)
return pip.main(['uninstall', '-y'] + pkgs)

return pip_new.main(['install'] + pkgs)
return pip_new.main(['uninstall', '-y'] + pkgs)

参考技术A 我的是Mac提示pip可以升级,然后出现了上述问题,使用的是python3.6,需要的是更新pip,在终端中输入:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
接着继续输入:
python3 get-pip.py
如果报错:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/bin/pip'
Consider using the `--user` option or check the permissions.
就改用:
sudo python3 get-pip.py
这样就更新好了
Successfully uninstalled pip-18.0
参考技术B 看看你的pip 版本,10.0没有main(),考虑降个版本:python -m pip install --upgrade pip==9.0.3 参考技术C python和 pip 不对应吧,,,,,,不然就是pip不是python的。。。。。。。

以上是关于AttributeError: module 'pip' has no attribute 'main'如何解决?的主要内容,如果未能解决你的问题,请参考以下文章

类 InstagramSpider(scrapy.Spider): AttributeError: 'module' 对象没有属性 'Spider'

api = twitter.Api() AttributeError: 'module' 对象没有属性 'Api

AttributeError:'module'对象在python中没有属性'windll'

如何修复python2.7中的“AttributeError:'module'对象没有属性'storage'”错误

成功解决AttributeError: module ‘numpy‘ has no attribute ‘polyld‘

hydra安装——AttributeError: module ‘hydra‘ has no attribute ‘main‘