module 'pip' has no attribute 'main'

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)

转载于:https://www.cnblogs.com/kunkunZeng/p/9114119.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值