我需要在python3中使用re2。安装工作正常,但当我导入它时,我收到此错误:
>>> import re2 as re
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "re2.pyx", line 1, in init re2 (src/re2.cpp:13681)
NameError: basestring
有谁知道问题是什么?
答案 0 :(得分:6)
发布到PyPI的版本不兼容Python 3; basestring
仅存在于Python 2中。这不是唯一的问题,修复以文本为中心的项目以适应Python 3全文是Unicode视图并非易事。
看来具体项目没有维护;其他人have already reported the problem,人们指出了另一个分支:https://github.com/andreasvc/pyre2。
您可以直接从GitHub安装该项目:
pip install git+https://github.com/andreasvc/pyre2.git
请注意,您需要先为该项目安装Cython才能编译;与其他fork不同,生成的C ++文件(来自re2.pyx
文件)未签入。只需运行pip install Cython
。
你也可以看看替代品;或许regex
module也符合您的要求。 regex
是re
的替代品,具有其他功能,例如大大改进的Unicode支持。