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

Error when pycharm installs flask

pycharm版本:2017.2.3
python版本:2.7
pip版本:10.0.1

report an error

write picture description here

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/packaging_tool.py", line 192, in main
    retcode = do_install(pkgs)
  File "/Applications/PyCharm.app/Contents/helpers/packaging_tool.py", line 109, in do_install
    return pip.main(['install'] + pkgs)
AttributeError: 'module' object has no attribute 'main'

reason

The main function in the new version of pip has changed, which is the reason for pycharm

Reference:
PyCharm 2017.3 reported an error in the pip10.0.0 version (module 'pip' has no attribute 'main')

solve

method one

通过 pip 命令手动安装

Method 2
According to the path in the error message

    "/Applications/PyCharm.app/Contents/helpers/packaging_tool.py"

Open the file, if you can't find the file in mac, you can open it with

$ vim "/Applications/PyCharm.app/Contents/helpers/packaging_tool.py"

After opening, find the following 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)

change into:

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)

Problem solved successfully

Guess you like

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