NameError: name ‘pip’ is not defined

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

The following error occurred when using the IntelliJ idea tool pip to install things:

Action to modify:

Find the corresponding path to the file C:: (users, administrator, intellijidea, 2017.1, config, plugins, python, helpers, packaging_ tool.py

Source code:

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)

After modification:

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)

PS: delete PIP in the last return

If after modification

CMD: Python – M PIP install — upgrade pip

If not:

At this time, you can only install it manually

http://www.lfd.uci.edu/~gohlke/pythonlibs/ Search this website for what you need (yaml)

Select the corresponding WHL file, download and remember the location

CMD command: PIP installd: \% pyyaml-3.13-cp37-cp37m-win_ amd64.whl

Similar Posts: