解决pycharm问题:module 'pip' has no attribute 'main'

前言:更新pip之后,Pycharm安装package出现报错:module 'pip' has no attribute 'main'

1.找到pycharm的安装目录下的 helpers/packaging_tool.py文件

2.修改代码

修改前:

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 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)

3.再次尝试pycharm安装就可以了

原文地址:https://www.cnblogs.com/guo2733/p/10524496.html