I need to use re2 in python3. The installation worked fine but when I import it I receive this error:
>>> 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
Does anyone know what the problem is?
The version released to PyPI is not Python 3 compatible; basestring
only exists in Python 2. This will not be the only problem, fixing a text-focused project to fit the Python 3 all-text-is-Unicode view is not trivial.
It appears the specific project is unmaintained; others have already reported the problem, and people have pointed to a different fork: https://github.com/andreasvc/pyre2.
You can install that project directly from GitHub:
pip install git+https://github.com/andreasvc/pyre2.git
Note that you'll need to install Cython first for that project to compile; unlike the other fork the generated C++ file (from the re2.pyx
file) is not checked in. Just run pip install Cython
.
You could also look at alternatives; perhaps the regex
module would fit your requirements as well. regex
is a drop-in replacement for re
with additional features, like vastly improved Unicode support.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With