今天在用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,搞定!