导入库时出现Python StanfordNLP软件包错误

时间:2019-04-09 01:05:52

标签: python stanford-nlp

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

pip install 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

1 个答案:

答案 0 :(得分:1)

该行:

return f"<{self.__class__.__name__} index={self.index};words={self.words}>"

表示该软件包适用于Python 3.6或更高版本。它返回一个f字符串,该字符串在3.6版中引入。您正在运行2.7版。

该升级了吗?