在pycharm中安装文件时,突然报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_install(pkgs): try: # import pip try: from pip._internal import main except Exception: from pip import main except ImportError: error_no_pip() # return pip.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 pip.main(['uninstall', '-y'] + pkgs) 注意:需要把最后的return语句也注释方可成功。