今天在用pycharm下載module的時候突然就報錯: module 'pip' has no attribute 'main'
解決辦法是找到Pycharm的安裝目錄下面的Contents/helpers下面的packaging_tool.py
把do_install 和 do_uninstall兩個方法從
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: 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,搞定!