Pycharm問題:module 'pip' has no attribute 'main'

更新pip以後(pip 10 版本以後),Pycharm安裝package出現報錯:module 'pip' has no attribute 'main'spa

解決辦法以下:code

找到Pycharm安裝目錄下的  helpers/packaging_tool.py 文件找到以下代碼:blog

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)

修改成以下便可:ip

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)
相關文章
相關標籤/搜索