导入库时Python StanfordNLP包错误

问题描述 投票:2回答:1

我刚刚安装了python stanford nlp,这很好: -

pip install 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
python stanford-nlp
1个回答
1
投票

这条线:

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

表示该程序包适用于Python 3.6或更高版本。它返回一个f-string,它是在3.6版本中引入的。您运行的是2.7版。

是时候升级?

© www.soinside.com 2019 - 2024. All rights reserved.