pycharm 报错:NameError: name ‘pip’ is not defined

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://www.cnblogs.com/Fordestiny/p/8901100.html

https://segmentfault.com/q/1010000014743128