module 'pip' has no attribute 'main'
Pycharm安装package出现报错:module 'pip' has no attribute 'main'
Traceback (most recent call last):
File "D:\Program Files\JetBrains\PyCharm Community Edition 2017.3.1\helpers\packaging_tool.py", line 192, in main
retcode = do_install(pkgs)
File "D:\Program Files\JetBrains\PyCharm Community Edition 2017.3.1\helpers\packaging_tool.py", line 109, in do_install
return pip.main(['install'] + pkgs)
AttributeError: module 'pip' has no attribute 'main'
参考解决:https://blog.csdn.net/yup1212/article/details/80047326
第104行
原文:
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)
还是出现报错
参考链接:https://segmentfault.com/q/1010000014743128
解决方案:之前更改packaging_tool.py时少改了一处。最后return处要把pip删掉。
最后修改为:
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 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 main(['uninstall', '-y'] + pkgs)