Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpaCy OSError: Can't find model 'en'

Tags:

nlp

spacy

even though I downloaded the model it cannot load it

[jalal@goku entity-sentiment-analysis]$ which python /scratch/sjn/anaconda/bin/python [jalal@goku entity-sentiment-analysis]$ sudo python -m spacy download en [sudo] password for jalal:  Collecting https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz   Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz (37.4MB)     100% |████████████████████████████████| 37.4MB 9.4MB/s  Installing collected packages: en-core-web-sm   Running setup.py install for en-core-web-sm ... done Successfully installed en-core-web-sm-2.0.0      Linking successful     /usr/lib/python2.7/site-packages/en_core_web_sm -->     /usr/lib64/python2.7/site-packages/spacy/data/en      You can now load the model via spacy.load('en')  import spacy   nlp = spacy.load('en') --------------------------------------------------------------------------- OSError                                   Traceback (most recent call last) <ipython-input-2-0fcabaab8c3d> in <module>()       1 import spacy       2  ----> 3 nlp = spacy.load('en')  /scratch/sjn/anaconda/lib/python3.6/site-packages/spacy/__init__.py in load(name, **overrides)      17             "to load. For example:\nnlp = spacy.load('{}')".format(depr_path),      18             'error') ---> 19     return util.load_model(name, **overrides)      20       21   /scratch/sjn/anaconda/lib/python3.6/site-packages/spacy/util.py in load_model(name, **overrides)     118     elif hasattr(name, 'exists'):  # Path or Path-like to model data     119         return load_model_from_path(name, **overrides) --> 120     raise IOError("Can't find model '%s'" % name)     121      122   OSError: Can't find model 'en' 

How should I fix this?

If I don't use sudo for downloading the en model, I get:

Collecting https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz   Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz (37.4MB)     100% |████████████████████████████████| 37.4MB 9.6MB/s ta 0:00:011   62% |████████████████████            | 23.3MB 8.6MB/s eta 0:00:02 Requirement already satisfied (use --upgrade to upgrade): en-core-web-sm==2.0.0 from https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz in /scratch/sjn/anaconda/lib/python3.6/site-packages You are using pip version 10.0.0, however version 10.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.      Error: Couldn't link model to 'en'     Creating a symlink in spacy/data failed. Make sure you have the required     permissions and try re-running the command as admin, or use a     virtualenv. You can still import the model as a module and call its     load() method, or create the symlink manually.      /scratch/sjn/anaconda/lib/python3.6/site-packages/en_core_web_sm -->     /scratch/sjn/anaconda/lib/python3.6/site-packages/spacy/data/en       Download successful but linking failed     Creating a shortcut link for 'en' didn't work (maybe you don't have     admin permissions?), but you can still load the model via its full     package name:      nlp = spacy.load('en_core_web_sm') 
like image 516
Mona Jalal Avatar asked Apr 22 '18 08:04

Mona Jalal


People also ask

What does spacy load (' en ') do?

Essentially, spacy. load() is a convenience wrapper that reads the pipeline's config. cfg , uses the language and pipeline information to construct a Language object, loads in the model data and weights, and returns it.

What is spacy Lang en?

The English language class in spacy. lang. en contains the language-specific code and rules included in the library – for example, special case rules for tokenization, stop words or functions to decide whether a word like "twenty two" resembles a number. spacy.


2 Answers

FINALLY CLEARED THE ERROR !!!

Best Way to Install now

pip install -U pip setuptools wheel  pip install -U spacy  python -m spacy download en_core_web_sm 

Always Open Anaconda Prompt / Command Prompt with Admin Rights to avoid Linking errors!!!

  • Tried multiple options including :

    python -m spacy download en

    conda install -c conda-forge spacy

    python -m spacy download en_core_web_sm

    python -m spacy link en_core_web_sm en

  • None worked since im using my Company's Network. Finally this Command Worked like a Charm :-)

    pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz --no-deps

    • Updated with Latest Link :

    pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz --no-deps

Thanks to the Updated Github Links :-)

like image 94
Vetrivel PS Avatar answered Sep 19 '22 03:09

Vetrivel PS


By using sudo python ... you install the model for a different python interpreter than your local one. In fact, it says in your log that the spaCy model is installed to /usr/lib64/python2.7/site-packages/ instead of /scratch/sjn/anaconda/lib/python3.6/site-packages/.

Try running python -m spacy download en and it should install the model to the correct directory.

like image 22
Johannes Gontrum Avatar answered Sep 20 '22 03:09

Johannes Gontrum