Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import error with spacy: "No module named en"

Tags:

python

spacy

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)

like image 996
The Coding Monk Avatar asked Jan 17 '16 18:01

The Coding Monk


3 Answers

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

like image 172
Burhan Khalid Avatar answered Oct 09 '22 16:10

Burhan Khalid


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')

like image 18
Wong Tat Yau Avatar answered Oct 09 '22 15:10

Wong Tat Yau


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.

like image 6
Bruno Caprettini Avatar answered Oct 09 '22 15:10

Bruno Caprettini