Not able to load English language module of spacy with spacy.load('en')
Asked Answered
Z

8

6

I am not able to load the English model in jupyter notebook with below code-

!pip install spacy
import spacy
spacy.load('en')

Error message:

OSError Traceback (most recent call last) in () ----> 1 spacy.load('en')

C:\ProgramData\Anaconda3\lib\site-packages\spacy_init_.py in load(name, **overrides) 19 if depr_path not in (True, False, None): 20 deprecation_warning(Warnings.W001.format(path=depr_path)) ---> 21 return util.load_model(name, **overrides) 22 23

C:\ProgramData\Anaconda3\lib\site-packages\spacy\util.py in load_model(name, **overrides) 117 elif hasattr(name, 'exists'): # Path or Path-like to model data 118 return load_model_from_path(name, **overrides) --> 119 raise IOError(Errors.E050.format(name=name)) 120 121

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

I have installed python version 2.7.15, 3.6.7, 3.7.1 and Anaconda3 5.3.1

I have downloaded the spacy package with

!pip install spacy

and English package with

python -m spacy download en

in anaconda prompt

Zooplankton answered 24/12, 2018 at 9:36 Comment(1)
Well, and which of the many Python versions are you using actually? Can you reduce your problem, e.g. to a simple script that can be started from the commandline?Pneumatophore
G
8

Edit: Based on your comments it seems you downloaded the model but couldn't link it. You do not have permission to do it, check here and give permission to current user. After that download model with same script:

python -m spacy download en

Check here, there is a brief description of the error.

Garv answered 24/12, 2018 at 10:59 Comment(7)
Thanks for your input I have tried but gives below error- Requirement already satisfied: en_core_web_sm==2.0.0 from github.com/explosion/spacy-models/releases/download/… in c:\programdata\anaconda3\lib\site-packages (2.0.0) Linking successful C:\ProgramData\Anaconda3\lib\site-packages\en_core_web_sm --> C:\ProgramData\Anaconda3\lib\site-packages\spacy\data\en You can now load the model via spacy.load('en') You do not have sufficient privilege to perform this operation.Zooplankton
Hm it's interesting, maybe you downloaded but not linked. While you are downloading the language did you face with this kind of error ? You do not have sufficient privilege to perform this operation.Garv
No, I did not face any error. While using spacy.load('en') I faced the error "You do not have sufficient privilege to perform this operation."Zooplankton
it shows the invalid syntax File "<ipython-input-6-fc4d5d118d23>", line 1 python -m spacy download en ^ SyntaxError: invalid syntaxZooplankton
Did you run it in notebook? If you running a command in notebook you need to add ! char to head of command like :!python -m spacy download enGarv
Yes, I run it in the notebook. I have tried with "!" and it gives the error seen in the 1st comment and if I try without "!" then it shows error reported in 3rd comment.Zooplankton
Why I got error OSError: [E049] Can't find spaCy data directory: 'None'. Check your installation and permissions, or use spacy.util.set_data_path to customise the location if necessary.?Jemima
S
3

I installed Spyder and anoconda which allowed me to run spacy but only in Spyder. Try that to see if you can run from there.

Update

Try using the following instead

pip install -U spacy
python -m spacy download en

The use this in your code:

import spacy
nlp = spacy.load('en')
Swinford answered 26/12, 2018 at 22:53 Comment(0)
M
3

I had the same issue. I'm using anaconda with windows. I solved it by following below steps.
Run anaconda prompt or command prompt as administrator and then run below commands.

pip install spacy python -m spacy download en

Mandelbaum answered 12/1, 2019 at 21:56 Comment(0)
P
1

If you are using windows, it could be that you have downloaded spacy model but symbolic link is failing. No worries, you can copy paste the folder manually to get it detected.

  1. Go to site-packages of your python.

  2. See the package you downloaded, for my case it was en_core_web_sm

  3. Copy and rename it to ../site-packages/spacy/data/en

Panthia answered 4/2, 2019 at 11:24 Comment(0)
A
0

Running anaconda prompt as an admin before installing any package solves all the problems. This way I did not have to double install modules using either pip3 or conda.

Amboina answered 13/8, 2020 at 12:22 Comment(0)
H
0

Open command prompt or terminal and execute the below code:

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

Execute the below chunk in your Jupiter notebook.

import spacy

nlp = spacy.load('en_core_web_sm')

Hope the above code works for all:)

Hickman answered 26/8, 2020 at 12:25 Comment(0)
S
0

I was building a script which uses spacy, but as I deploy this on dataproc clusters which are provisioned everytime, the spacy models won't be downloaded by default. So what I did was trying to import the model, if it isn't downloaded, download & load it.

def load_spacy_model(model_name):
    excluded_steps = ["tagger", "parser", "ner", "entitiy_linker", 
                      "entity_ruler", "textcat", "morphologizer",
                      "attribute_ruler", "senter", "sentencizer", 
                      "token2vec", "transformer"]
    try:
        spacy_model = spacy.load(model_name, exclude=excluded_steps)
    except OSError:
        spacy.cli.download(model_name)
        spacy_model = spacy.load(model_name, exclude=excluded_steps)
    return spacy_model
Synesthesia answered 17/2, 2021 at 13:34 Comment(0)
Q
0

Use only this;

import spacy

nlp = spacy.load("en_core_web_sm")

here 'en' in 'en_core_web_sm' means "English".

For Windows Python Install, You don't need to use this;

nlp = spacy.load('en') # Just delete it or comment it.

If you go to SpaCy documentation page; https://spacy.io/usage/models

when you change Language dropdown list selection to other language, the syntax of; "nlp = spacy.load('en_core_web_sm')" will change automatically according to your selection. For example, for Franch Language(after import spacy) the syntax will be;

nlp = spacy.load("fr_core_news_sm")

Quisling answered 30/5, 2021 at 0:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.