pycharm通过 File --> Settings --> Project Interpreter --> Available Packages 安装第三方包失败时报错信息为 Error:Exception
找到pycharm安装目录下helpers
下的 packaging_tool.py
修改 do_install
和 do_uninstall
这两个方法:
def do_install(pkgs):
# try:
# import pip
# except ImportError:
# error_no_pip()
# return pip.main(['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:
# import pip
# except ImportError:
# error_no_pip()
# return pip.main(['uninstall', '-y'] + pkgs)
try:
try:
from pip._internal import main
except Exception:
from pip import main
except ImportError:
error_no_pip()
return main(['uninstall', '-y'] + pkgs)
修改完成后重启pycharm(有时候不重启也能生效)