Ailef
Ailef

Reputation: 7906

Import error with spacy: "No module named en"

I'm having trouble using the Python spaCy library. It seems to be installed correctly but at

from spacy.en import English

I get the following import error:

Traceback (most recent call last):
  File "spacy.py", line 1, in <module>
    from spacy.en import English
  File "/home/user/CmdData/spacy.py", line 1, in <module>
    from spacy.en import English
ImportError: No module named en

I'm not very familiar with Python but that's the standard import I saw online, and the library is installed:

$ pip list | grep spacy
spacy (0.99)

EDIT I tested renaming the file, but that's not the problem. I also get the same error when doing:

$ python -m spacy.en.download --force all
/usr/bin/python: No module named en

(The command is supposed to download some models)

Upvotes: 13

Views: 35271

Answers (6)

Harshal SG
Harshal SG

Reputation: 453

This Works!

import spacy
import en_core_web_sm
nlp = en_core_web_sm.load()

Upvotes: 1

KPandian
KPandian

Reputation: 1198

SpaCy has various models depending on the language of your choice (even contains a multi-language model), so you can have a look at this link to have a better idea on which might suit your needs.

You could also find the correct installation command here. For example, for small version model for English Language:

python -m spacy download en_core_web_sm

Hope it helps!

Upvotes: 3

Bruno Caprettini
Bruno Caprettini

Reputation: 61

I had the same issue, and the problem was the folder where the module 'en' was stored (spacy/lang/en).

Typing:

from spacy.lang.en import English

fixed the issue.

This post was helpful in figuring this out.

Upvotes: 6

Wong Tat Yau
Wong Tat Yau

Reputation: 983

For windows, open cmd with admin right. Then,

python -m spacy download en 

You should see the shell prompt stating.

You can now load the model via spacy.load('en')

Upvotes: 18

user7185728
user7185728

Reputation: 49

It is possible that the version of Python at /usr/bin/python is not the one that has spacy installed. If so, navigating to the directory where your 'normal' version of Python is before running

python -m spacy.en.download

should fix the problem. (For example, I installed spacy using Anaconda and had to navigate to C:\Anaconda2\ first.)

Upvotes: 4

Burhan Khalid
Burhan Khalid

Reputation: 174624

You are facing this error because you named your own file spacy.py. Rename your file, and everything should work.

Upvotes: 14

Related Questions