'ImportError: No module named 'spacy.en'
I'm working on a codebase that uses Spacy. I installed spacy using:
sudo pip3 install spacy
and then
sudo python3 -m spacy download en
At the end of this last command, I got a message:
Linking successful
/home/rayabhik/.local/lib/python3.5/site-packages/en_core_web_sm -->
/home/rayabhik/.local/lib/python3.5/site-packages/spacy/data/en
You can now load the model via spacy.load('en')
Now, when I try running my code, on the line:
from spacy.en import English
it gives me the following error:
ImportError: No module named 'spacy.en'
I've looked on Stackexchange and the closest is: Import error with spacy: "No module named en" which does not solve my problem.
Any help would be appreciated. Thanks.
Edit: I might have solved this by doing the following:
Python 3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import spacy
>>> spacy.load('en')
<spacy.lang.en.English object at 0x7ff414e1e0b8>
and then using:
from spacy.lang.en import English
I'm still keeping this open in case there are any other answers.
Solution 1:[1]
I used the following command for installing spacy from anaconda distribution.
conda install -c conda-forge spacy
and after that, I was able to download English using the following command without any error.
python -m spacy download en
Solution 2:[2]
I had to use en_core_web_sm instead of en to make that work. It is complaining about permission problem. The following works perfectly:
import spacy
spacy.load('en_core_web_sm')
from spacy.lang.en import English
Solution 3:[3]
I think that there is a confusion in the answers provided. Correct things mentioned:
- you should import from spacy.lang.en
- spacy.load('en') is indeed a shortcut for loading models.
But: the file en_core_web_sm is not the same file as the one you import from spacy.lang.en. Actually, the first file is produced from the second after training with spacy train in a dataset and then packaging the result. spacy.lang.en contains the model definition: lemmas lookup table, stop_words, lexical attributes (and more). But that and only that. It is not trained with a dataset so that the dependency graph and other functionalities can work.
I think this should be clear enough when working with spaCy.
Solution 4:[4]
pip install spacy
python -m spacy download en
This works for me
Solution 5:[5]
the en_core_web_sm folder was downloaded outside the spacy folder. I copied it into the spacy/data folder and could run the code as documented in spacy
Solution 6:[6]
Anyone facing this issue on Windows 10 and Anaconda installation , look for your conda python executable using where python on command line before running the script.
In my case, the python on the PATH was
C:\Users\XXX\.windows-build-tools\python27\python.exe
whereas what I needed was from
c:\Users\XXX\AppData\Local\Continuum\anaconda3\python.exe
Just add the correct python on the path , or go to this location and run
python -m spacy download en
and it should work.
Solution 7:[7]
According to the official website you should do as follow:
python -m spacy download en
However, this surprisingly does NOT work for me.
As you may interst, my env is based on OSX 10.15 with python 3.8, pip 19.3.1
try:
spacy download en
Solution 8:[8]
For me what worked are these steps:
import sys
!{sys.executable} -m pip install spacy
!{sys.executable} -m spacy download en
I run these steps at my spyder console (installed through anaconda)
Solution 9:[9]
Anaconda Users
If you're using a conda virtual environment, be sure that its the same version of Python as that in your base environment. To verify this, run
python --versionin each environment. If not the same, create a new virtual environment with that version of Python (Ex.conda create --name myenv python=x.x.x).Activate the virtual environment (
conda activate myenv)conda install -c conda-forge spacypython -m spacy download en_core_web_sm
I just ran into this issue, and the above worked for me. This addresses the issue of the download occurring in an area that is not accessible to your current virtual environment.
You should then be able to run the following:
import spacy
nlp = spacy.load("en_core_web_sm")
Solution 10:[10]
from spacy.lang.en import English instead of from spacy.en import English
Solution 11:[11]
my solutions for en and fr and it
!pip install spacy
!python -m spacy download en
!python -m spacy download it
!python -m spacy download fr
then
import spacy
spacy.load('en')
spacy.load('it')
spacy.load('fr')
Solution 12:[12]
For me the below steps worked in my Jupyter:
pip install spacy
import spacy
from spacy.cli import download
print(download('en_core_web_sm'))
Solution 13:[13]
I solved it by:
import spacy.cli
spacy.cli.download("en_core_web_lg")
Hope it helps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
