解決pycharm問題:module 'pip' has no attribute 'main'

今天在用pycharm下載module的時候忽然就報錯: module 'pip' has no attribute 'main'spa

解決辦法是找到Pycharm的安裝目錄下面的Contents/helpers下面的packaging_tool.pycode

把do_install 和 do_uninstall兩個方法從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:
        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:
        try:
            from pip._internal import main
        except Exception:
            from pip import main
    except ImportError:
        error_no_pip()
    return main(['uninstall', '-y'] + pkgs)

從新啓動Pycharm,搞定!pycharm

相關文章
相關標籤/搜索