2017-10-17 164 views
1

我需要在python3中使用re2。安装工作正常,但是当我导入它时,我收到此错误:在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

我刚刚安装了build-essential libre2-dev的形式aptitude,然后通过pip的re2! – user1829243

回答

4

发布到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为该项目编制;与其他分支不同,生成的C++文件(来自re2.pyx文件)没有签入。只需运行pip install Cython

你也可以看看替代品;也许regex module也符合你的要求。 regexre的附加功能的替代替代品,如大大改进的Unicode支持。