问题简述: 环境:deepin15+Anaconda3,在执行pip时报错如下:
Traceback (most recent call last):
File "/usr/share/Anaconda3/bin/pip", line 7, in
from pip._internal import main
File "/usr/share/Anaconda3/lib/python3.6/site-packages/pip/_internal/__init__.py", line 42, in
from pip._internal import cmdoptions
File "/usr/share/Anaconda3/lib/python3.6/site-packages/pip/_internal/cmdoptions.py", line 16, in
from pip._internal.index import (
File "/usr/share/Anaconda3/lib/python3.6/site-packages/pip/_internal/index.py", line 15, in
from pip._vendor import html5lib, requests, six
File "/usr/share/Anaconda3/lib/python3.6/site-packages/pip/_vendor/requests/__init__.py", line 86, in
from pip._vendor.urllib3.contrib import pyopenssl
File "/usr/share/Anaconda3/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.py", line 46, in
import OpenSSL.SSL
File "/usr/share/Anaconda3/lib/python3.6/site-packages/OpenSSL/__init__.py", line 8, in
from OpenSSL import crypto, SSL
File "/usr/share/Anaconda3/lib/python3.6/site-packages/OpenSSL/crypto.py", line 12, in
from cryptography import x509
File "/usr/share/Anaconda3/lib/python3.6/site-packages/cryptography/x509/__init__.py", line 8, in
from cryptography.x509.base import (
File "/usr/share/Anaconda3/lib/python3.6/site-packages/cryptography/x509/base.py", line 16, in
from cryptography.x509.extensions import Extension, ExtensionType
File "/usr/share/Anaconda3/lib/python3.6/site-packages/cryptography/x509/extensions.py", line 13, in
from asn1crypto.keys import PublicKeyInfo
File "/usr/share/Anaconda3/lib/python3.6/site-packages/asn1crypto/keys.py", line 22, in
from ._elliptic_curve import (
File "/usr/share/Anaconda3/lib/python3.6/site-packages/asn1crypto/_elliptic_curve.py", line 51, in
from ._int import inverse_mod
File "/usr/share/Anaconda3/lib/python3.6/site-packages/asn1crypto/_int.py", line 52, in
if platform.python_implementation() == 'PyPy':
File "/usr/share/Anaconda3/lib/python3.6/platform.py", line 1257, in python_implementation
return _sys_version()[0]
File "/usr/share/Anaconda3/lib/python3.6/platform.py", line 1215, in _sys_version
repr(sys_version))
ValueError: failed to parse CPython sys.version: '3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19) \n[GCC 7.2.0]'
问题定位: /usr/share/Anaconda3/lib/python3.6/platform.py:1215:
# CPython match = _sys_version_parser.match(sys_version) if match is None : raise ValueError ( 'failed to parse CPython sys.version: %s ' % repr (sys_version)) version, buildno, builddate, buildtime, compiler = \ match.groups() _sys_version_parser:
_sys_version_parser = re.compile( r ' ([ \w.+ ] + ) \s * ' # "version" r ' \( # ? ([^ , ] + ) ' # "(#buildno" r ' (?: ,\s * ([ \w ] * ) ' # ", builddate" r ' (?: ,\s * ([ \w : ] * )) ? ) ?\) \s * ' # ", buildtime)" r ' \[ ([^ \] ] + ) \]? ' , re.ASCII) # "[compiler]" 发现此正则表达式未考虑Anaconda增加了"|Anaconda, Inc.|"的问题,需要过滤掉.
解决方法:
在_sys_version_parser中增加一行过滤掉"|Anaconda xxx|"等信息即可:
_sys_version_parser = re.compile( r ' ([ \w.+ ] + ) \s * ' # "version" r ' (?: \| [^ | ] *\| ) * \s * ' #去掉'|Anaconda xxx|'等,避免出现failed to parse CPython sys.version r ' \( # ? ([^ , ] + ) ' # "(#buildno" r ' (?: ,\s * ([ \w ] * ) ' # ", builddate" r ' (?: ,\s * ([ \w : ] * )) ? ) ?\) \s * ' # ", buildtime)" r ' \[ ([^ \] ] + ) \]? ' , re.ASCII) # "[compiler]"
【解决Anaconda执行pip等命令报alueError: failed to parse CPython sys.version错误的问题】
推荐阅读
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- Python专栏|数据分析的常规流程
- Python|Win10下 Python开发环境搭建(PyCharm + Anaconda) && 环境变量配置 && 常用工具安装配置
- Python绘制小红花
- Pytorch学习|sklearn-SVM 模型保存、交叉验证与网格搜索
- OpenCV|OpenCV-Python实战(18)——深度学习简介与入门示例
- python|8. 文件系统——文件的删除、移动、复制过程以及链接文件
- 爬虫|若想拿下爬虫大单,怎能不会逆向爬虫,价值过万的逆向爬虫教程限时分享
- 分布式|《Python3网络爬虫开发实战(第二版)》内容介绍
- java|微软认真聆听了开源 .NET 开发社区的炮轰( 通过CLI 支持 Hot Reload 功能)