pycharm出现问题:AttributeError: module 'pip' has no attribute 'main'

pycharm出现问题:AttributeError: module 'pip' has no attribute 'main'_第1张图片
环境信息:pycharm2017.3.1(Professional Edition)、python3.6.5 (64位)、pip10.0.1、Django2.0.5

错误原因:由于pip 10版本中没有main(),如果在不降级的情况下,修改这个文件

找到pycharm安装目录下的packaging_tool.py修改成如下内容
D:\Program Files\JetBrains\PyCharm 2017.3.4\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 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)

你可能感兴趣的:(Pycharm)