pycharm問題:module ‘pip’ has no attribute ‘main’

更新pip之後,Pycharm安裝package出現報錯:module ‘pip’ has no attribute ‘main’
找到安裝目錄下 helpers/packaging_tool.py文件,找到如下代碼:

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

轉自:
《解決pycharm問題:module ‘pip’ has no attribute ‘main’》
http://www.cnblogs.com/Fordestiny/p/8901100.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章