1. 程式人生 > >pycharm問題:module 'pip' has no attribute 'main'外掛安裝失敗

pycharm問題:module 'pip' has no attribute 'main'外掛安裝失敗

在這裡插入圖片描述

在這裡插入圖片描述

找到D:\Program Files\JetBrains\PyCharm 2017.2\helpers 的packaging_tool.py檔案:
104行-117行

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)

安裝外掛方法

一、pywin32 、Twisted 需要下載檔案再安裝

下載Twisted

https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml 

下載pywin32

https://sourceforge.net/projects/pywin32/files/pywin32/Build 221/

二、lxml、beautifulsoup4、wheel、requests、pyOpenSSL、Scrapy

都可在pycharm中一鍵下載外掛,且scrapy最後下載