13

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)

The Coding Monk
  • 7,684
  • 12
  • 41
  • 56

6 Answers6

18

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

Wong Tat Yau
  • 953
  • 11
  • 11
14

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

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • 3
    Do you have a `spacy.pyc` file in the same directory form where you are running the command? If so, delete it. – Burhan Khalid Jan 17 '16 at 18:38
  • @TheCodingMonk Can I follow up and ask how did you solve the problem? I had the same problem but don't understand the conversations above. Thanks ! – yuqli Nov 21 '17 at 20:53
6

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.

  • 1
    I was looking for the new location for stopwords in Spacy and your post was helpful. from spacy.lang.en import STOP_WORDS as STOPWORDS – Nic Scozzaro Feb 25 '18 at 18:58
4

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

user7185728
  • 49
  • 1
  • 1
3

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!

KPandian
  • 1,148
  • 9
  • 8
1

This Works!

import spacy
import en_core_web_sm
nlp = en_core_web_sm.load()
Harshal SG
  • 403
  • 3
  • 7