码迷,mamicode.com
首页 > 其他好文 > 详细

module 'pip' has no attribute 'main'

时间:2018-05-31 00:17:49      阅读:567      评论:0      收藏:0      [点我收藏+]

标签:log   info   rac   1.7   call   更改   pkg   出现   charm   

Pycharm安装package出现报错:module ‘pip‘ has no attribute ‘main‘
 技术分享图片
Traceback (most recent call last):
File "D:\Program Files\JetBrains\PyCharm Community Edition 2017.3.1\helpers\packaging_tool.py", line 192, in main
retcode = do_install(pkgs)
File "D:\Program Files\JetBrains\PyCharm Community Edition 2017.3.1\helpers\packaging_tool.py", line 109, in do_install
return pip.main([‘install‘] + pkgs)
AttributeError: module ‘pip‘ has no attribute ‘main‘
 
参考解决:https://blog.csdn.net/yup1212/article/details/80047326
第104行
原文:
def do_install(pkgs):
    try:
        import pip
    except ImportError:
        error_no_pip()
    return pip.main([install] + pkgs)


def do_uninstall(pkgs):
    try:
        import pip
    except ImportError:
        error_no_pip()
    return pip.main([uninstall, -y] + pkgs)

改为:

def do_install(pkgs):
    try:
        # import pip
        try:
            from pip._internal import main
        except Exception:
            from pip import main
    except ImportError:
        error_no_pip()
    return pip.main([install] + pkgs)


def do_uninstall(pkgs):
    try:
        # import pip
        try:
            from pip._internal import main
        except Exception:
            from pip import main
    except ImportError:
        error_no_pip()
    return pip.main([uninstall, -y] + pkgs)

还是出现报错

技术分享图片
参考链接:https://segmentfault.com/q/1010000014743128
解决方案:之前更改packaging_tool.py时少改了一处。最后return处要把pip删掉。
最后修改为:
def do_install(pkgs):
    try:
        # import pip
        try:
            from pip._internal import main
        except Exception:
            from pip import main
    except ImportError:
        error_no_pip()
    return main([install] + pkgs)


def do_uninstall(pkgs):
    try:
        # import pip
        try:
            from pip._internal import main
        except Exception:
            from pip import main
    except ImportError:
        error_no_pip()
    return main([uninstall, -y] + pkgs)

module 'pip' has no attribute 'main'

标签:log   info   rac   1.7   call   更改   pkg   出现   charm   

原文地址:https://www.cnblogs.com/kunkunZeng/p/9114119.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!