尝试在Jupyter笔记本中安装Stanza CoreNLP界面时出现属性错误

问题描述

我正在尝试在Jupyter笔记本中使用Stanza。这是我使用的代码

!pip install stanza
import stanza

corenlp_dir = './corenlp'
stanza.install_corenlp(dir=corenlp_dir)

# Set the CORENLP_HOME environment variable to point to the installation location
import os
os.environ["CORENLP_HOME"] = corenlp_dir

代码直接来自Stanza CoreNLP界面教程this Colab notebook

但是,当我在自己的Jupyter笔记本(Python 3.7.4)上运行它时,出现以下错误

AttributeError: module 'stanza' has no attribute 'install_corenlp'

在行上出现

stanza.install_corenlp(dir=corenlp_dir)

在此之前的所有其他行都可以正常工作。检查文档表明这是Python 2中的问题,但是我的Jupyter笔记本正在运行3.7.4。这是什么问题,我应该如何解决

解决方法

也许您的计算机安装了Python 2而不是Python3。请确保Jupyter笔记本和计算机都具有相同版本的Python。您还应该确保计算机上也安装了Java。

,

事实证明,我在Jupyter Notebook中安装Stanza安装时出现了问题。似乎我的Stanza是较旧的版本(尽管上周才安装了Stanza,但我还是设法安装了过时的版本),不得不使用命令重新安装它

!pip install stanza -U

即使这样做,实际上直到我在笔记本上重新启动Jupyter内核时,问题才得以解决。然后只有安装才真正能够进行。