1. 程式人生 > >解決pycharm問題:module ‘pip‘ has no attribute ‘main‘

解決pycharm問題:module ‘pip‘ has no attribute ‘main‘

article 卸載 根據 sta 建議 pack blog htm tin

一:可能性解決方法一
《解決pycharm問題:module ‘pip‘ has no attribute ‘main‘》
http://www.cnblogs.com/Fordestiny/p/8901100.html
https://blog.csdn.net/yup1212/article/details/80047326
更新pip之後,Pycharm安裝package出現報錯:module ‘pip‘ has no attribute ‘main‘

找到安裝目錄下 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)

可能性解決方法二:
在控制臺輸入pip,根據提示安裝,如果還是報版本的錯誤,建議根據提示,先卸載,再安裝相應的版本
pip install --user nltk

解決pycharm問題:module ‘pip‘ has no attribute ‘main‘