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

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

在使用pyCharm创建项目的时候发现了如题目的错误,网上找了一下发现是因为main不在pip包里了。

解决办法
找到安装目录下 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)

你可能感兴趣的:(解决PyCharm问题:AttributeError: module 'pip' has no attribute 'main')