简体   繁体   English

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

[英]Attribute error when attempting to install Stanza CoreNLP interface in Jupyter notebook

I am trying to use Stanza in a Jupyter notebook.我正在尝试在 Jupyter 笔记本中使用 Stanza。 This is the code I used:这是我使用的代码:

!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

This code is taken directly from this Colab notebook , a tutorial on the Stanza CoreNLP interface.此代码直接取自Colab 笔记本,这是一个关于 Stanza CoreNLP 界面的教程。

However, when I run it on my own Jupyter notebook (Python 3.7.4), I get the following error:但是,当我在自己的 Jupyter 笔记本(Python 3.7.4)上运行它时,出现以下错误:

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

which occurs at the line发生在该行

stanza.install_corenlp(dir=corenlp_dir)

All other lines before that work fine.在此之前的所有其他行都可以正常工作。 Checking documentation suggests that this is an issue in Python 2, but my Jupyter notebook is running 3.7.4.检查文档表明这是 Python 2 中的一个问题,但我的 Jupyter notebook 运行的是 3.7.4。 What is the issue here and how should I resolve it?这里有什么问题,我应该如何解决?

Maybe your computer has Python 2 installed instead of Python 3. Make sure both the Jupyter notebook and your computer both have the same version of Python.也许您的计算机安装了 Python 2 而不是 Python 3。确保 Jupyter notebook 和您的计算机都安装了相同版本的 Python。 You should also make sure that you have Java installed on your computer as well.您还应该确保您的计算机上也安装了 Java。

It turns out that there was an issue with my Stanza installation in Jupyter Notebook .事实证明,我在 Jupyter Notebook 中的Stanza 安装存在问题。 Seems my Stanza had been an older version (I somehow managed to install an outdated version of Stanza despite installing it just last week) and had to reinstall it with the command似乎我的 Stanza 是一个旧版本(尽管上周才安装了它,但我还是设法安装了一个过时的 Stanza 版本)并且不得不使用命令重新安装它

!pip install stanza -U

Even after doing so, the issue was actually not resolved until I restarted the Jupyter kernel across the notebook .即使这样做了,问题实际上也没有解决,直到我在笔记本上重新启动 Jupyter 内核 Then only the installation was actually able to take place.然后只有安装才能真正进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM