AttributeError: module 'pip' has no attribute 'main'

pip安装模块是报错如下:

解决方法:

找到安装路径下的packaging_tool.py文档修改如下:

我的路径为D:\Program Files\JetBrains\PyCharm 2017.2.3\helpers\packaging_tool.py

原先:

修改后保存退出即可:

代码如下:

def do_install(pkgs):
    try:
        try:
            from pip._internal import main
        except Exception:
            from pip import main 
        #import pip
    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 
        #import pip
    except ImportError:
        error_no_pip()
    return main(['uninstall', '-y'] + pkgs)

 注意:return 没有pip,然后缩进的问题。

 

关键词:pip main import from pkgs except try return module attributeerror

相关推荐:

修复:pip 'module' object has no attribute '_handlerList'

Python: Calling python functions from mako templates

Python爬虫html解析工具beautifulSoup在pycharm中安装及失败的解决办法

Django ImportError: No module named & hellip; But the module is visible in the p...

pip ImportError: cannot import name main

AttributeError: module ‘paramiko’ has no attribute ‘SSHClient’

pycharm安装 package报错:module 'pip' has no attribute 'main'