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

1.3k views Asked by At

I am trying to use Stanza in a Jupyter notebook. 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.

However, when I run it on my own Jupyter notebook (Python 3.7.4), I get the following error:

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. What is the issue here and how should I resolve it?

2

There are 2 answers

0
Ryan Chng On BEST ANSWER

It turns out that there was an issue with my Stanza installation in Jupyter Notebook. 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

!pip install stanza -U

Even after doing so, the issue was actually not resolved until I restarted the Jupyter kernel across the notebook. Then only the installation was actually able to take place.

0
balexander1 On

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. You should also make sure that you have Java installed on your computer as well.