explosion/spaCy

OSError: [E050] Can't find model 'en_core_web_sm'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.

icmpnorequest opened this issue ยท 7 comments

I have installed spacy and downloaded en_core_web_sm with:

pip3 install spacy
python3 -m spacy download en_core_web_sm

When running codes on Python3 default IDLE, it runs successfully:

import spacy
spacy.load("en_core_web_sm")

However, when I run above codes in jupyter notebook, it shows error:

OSError: [E050] Can't find model 'en_core_web_sm'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.

I tried several ways in Jupyter notebook like

!python3 -m spacy download en_core_web_sm

but it still shows the error.

OS: MacOS

Could somebody help me fix this issue? Thanks in advance!

ines commented

Which version of spacy are you running? If you're not using the latest, try upgrading.

One common problem with Jupyter notebooks is that they install packages (including spaCy models, which are also just Python packages) in the same Python session and the installed packages are not automatically refreshed. This makes it difficult to detect whether a package is installed or not. More recent versions of spaCy should include a workaround for this.

Also make sure that the python / python3 you're executing within your notebook actually refers to the same environment you're running your notebook in.

@ines

I have tried to update my spaCy with !pip3 install -U spacy and !python3 -m spacy download en_core_web_sm in Jupyter notebook.

My spaCy version: 2.2.2
My Python version: 3.7.2

However, when input spacy.load('en_core_web_sm'), it still shows the error:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-14-ec4f59b9cf67> in <module>
----> 1 spacy.load('en_core_web_sm')

/usr/local/lib/python3.7/site-packages/spacy/__init__.py in load(name, **overrides)
     28     if depr_path not in (True, False, None):
     29         deprecation_warning(Warnings.W001.format(path=depr_path))
---> 30     return util.load_model(name, **overrides)
     31 
     32 

/usr/local/lib/python3.7/site-packages/spacy/util.py in load_model(name, **overrides)
    218     elif hasattr(name, "exists"):  # Path or Path-like to model data
    219         return load_model_from_path(name, **overrides)
--> 220     raise IOError(Errors.E050.format(name=name))
    221 
    222 

OSError: [E050] Can't find model 'en_core_web_sm'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.
ines commented

What happens if you run the following?

import en_core_web_sm
nlp = en_core_web_sm.load()

If this works, it'd indicate that the problem is related to the way spaCy detects installed packages. If it doesn't work and gives you an ImportError, it means that the Python environment the model was installed in is not the same as your Jupyter environment.

Also, maybe double-check that the model installed correctly? Models are installed as Python packages by running pip in a subprocess. And pip errors can sometimes be a bit subtle and not immediately obvious in the output.

Finally, solve the issue by following:

pip3 install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz

I'm wondering what's the difference between these two command lines for installing en_core_web_sm ?

python3 -m spacy download en_core_web_sm
pip3 install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz

Thank you for patience and guidance!

ines commented

Glad it worked!

I'm wondering what's the difference between these two command lines for installing en_core_web_sm ?

When you run python -m spacy download en_core_web_sm, it will pretty much execute the same thing (pip install [link]), with pip running in a subprocess. The download also takes care of finding you the right version of the model and outputting helpful messages.

However, if the pip executed with python3 -m pip install isn't the same as pip3 install, it may execute the wrong pip and install the model in a different environment. In most environments, this is not a problem โ€“ but if it is, installing the models directly via the link is a fine solution.

(In the future, this will hopefully also be less of an issue, because Python 2 will be less common and python3 and pip3 will become python and pip again.)

import en_core_web_sm
nlp = en_core_web_sm.load()

@ines This fixed it for me. Thanks!

lock commented

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.