我刚刚安装了 python stanford nlp,运行良好:-
pip 安装 stanfordnlp
我在 python shell 中尝试实例化包,但出现以下错误:-
>>> import stanfordnlp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shivajidutta/anaconda/lib/python2.7/site-packages/stanfordnlp/__init__.py", line 1, in <module>
from stanfordnlp.pipeline.core import Pipeline
File "/Users/shivajidutta/anaconda/lib/python2.7/site-packages/stanfordnlp/pipeline/core.py", line 9, in <module>
from stanfordnlp.pipeline.doc import Document
File "/Users/shivajidutta/anaconda/lib/python2.7/site-packages/stanfordnlp/pipeline/doc.py", line 175
return f"<{self.__class__.__name__} index={self.index};words={self.words}>"
^
SyntaxError: invalid syntax
请您参考如下方法:
行:
return f"<{self.__class__.__name__} index={self.index};words={self.words}>"
表示该包适用于 Python 3.6 或更高版本。它返回一个 f 字符串,这是在 3.6 版中引入的。您正在运行 2.7 版。
是时候升级了吗?
