故障处理:pip10 升级后,PyCharm,python package tools not found

一、背景

     升级pycharm 2018版前,当前mac系统未做升级,TSL/SSL证书的问题导致pip失效(mac系统的支持问题),当时为其他包做更新时,测试时升级了pip至pip10;升级系统至MacOS High Sierra(10.13.4)后,mac系统终于解决SSL问题,此时查看pycharm,发现pip安装包不可用。

二、故障现象

报错现象1:

执行pip命令报错,如下
Traceback (most recent call last):
  File "/usr/local/bin/pip2", line 7, in 
    from pip import main
ImportError: cannot import name main


报错现象2:
pycharm ,python package tools not found,install 安装报错

报错现象3:

easy_install命令报错

Traceback (most recent call last):
  File "/usr/local/bin/easy_install", line 6, in 
    from pkg_resources import load_entry_point
  File "/Users/Andy/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 72, in 
    import packaging.requirements
  File "/Users/Andy/Library/Python/2.7/lib/python/site-packages/packaging/requirements.py", line 59, in 
    MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")
TypeError: __call__() takes exactly 2 arguments (1 given)


三、原因

1. 升级pip10后,对应2.7版本需要修改pip文件,main不在pip package下,而在pip._internal中
2. PyCharm 安装包会调用pip及easy_install


四、解决方法

第一步:vi /usr/local/bin/pip(视具体环境),替换“ from pip import main”语句为“ from pip._internal import main as main”

# -*- coding: utf-8 -*-
import re
import sys
#from pip import main
from pip._internal import main as main
if __name__ == '__main__':
     sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
     sys.exit(main())




第二步:更新easy_install
pip install --upgrade setuptools --user python



更新后,重启终端及PyCharm,再次验证即可

你可能感兴趣的:(Python)