巴拉巴拉
小魔仙

PyCharm更新pip到18.0报错AttributeError: module ‘pip’ has no attribute ‘main’

刚刚给PyCharm更新pip报错了

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


打开文件
/Applications/PyCharm.app/Contents/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)
    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 pip.main(['uninstall', '-y'] + pkgs)
    return main(['uninstall', '-y'] + pkgs)
赞(0) 打赏
如果文章对你有帮助,欢迎你来评价反馈。AgainFly » PyCharm更新pip到18.0报错AttributeError: module ‘pip’ has no attribute ‘main’

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  • Q Q(选填)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏