Solve the pycharm problem: module 'pip' has no attribute 'main'

When I downloaded the module with pycharm today, I suddenly reported an error:  module 'pip' has no attribute 'main'

The solution is to find packaging_tool.py under Contents/helpers under the Pycharm installation directory

Change the do_install and do_uninstall methods from

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)

 

Change it to:

def do_install(pkgs):
    try:
        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:
        try:
            from pip._internal import main
        except Exception:
            from pip import main
    except ImportError:
        error_no_pip()
    return main(['uninstall', '-y'] + pkgs)

Restart Pycharm and you're done!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325897436&siteId=291194637