我刚刚安装了python stanford nlp,它运行良好:-

pip安装stanfordnlp

从python外壳程序,我试图实例化该程序包,并得到以下错误:-

>>> 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版。

是时候升级了吗?

08-25 00:32