解决pycharm问题:module 'pip' has no attribute 'main'

转自:《解决pycharm问题:module 'pip' has no attribute 'main'》
原址: http://www.cnblogs.com/Fordestiny/p/8901100.html


其他建议:感谢评论区 痴缠一生 提醒 此bug时可能使用的是 pycharm-professional-2017.1.3 更新pycharm无此现象

其他建议:建议直接使用pip命令,比pycharm点点点舒服


更新pip之后,Pycharm安装package出现报错: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 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)

原贴是图片重新敲了一遍:https://blog.csdn.net/yup1212/article/details/80047326

你可能感兴趣的:(报错:软件本身的bug,语言:Python,工具:IDE)