Pycharm 解决pip遇到的错误:module 'pip' has no attribute 'main'

在pycharm中安装包是出现了如下错误:

“AttributeError: module 'pip' has no attribute 'main'”

解决:

修改pycharm安装目录下helpers\packaging_tool.py文件。修改do_install和do_uninstall如下:

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)

保存后即可正常使用。

你可能感兴趣的:(Python学习)