PyCharm can't find Spacy Model 'en'
Asked Answered
D

7

8

I am trying to load a NLP model 'en' from SpaCy in my PyCharm and I am using Python 2.7 .
My code to load the 'en' model is nlp = spacy.load('en', disable=['parser', 'ner'])
However, I received the following error
IOError: [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 then realised that I didn't download the model, so I used the terminal provided in PyCharm to download the model, I used python -m spacy download en

This was the following output:

Requirement already satisfied: en_core_web_sm==2.0.0 from https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0. tar.gz#egg=en_core_web_sm==2.0.0 in c:\python27\lib\site-packages
You are using pip version 9.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
You do not have sufficient privilege to perform this operation.

Linking successful C:\Python27\lib\site-packages\en_core_web_sm --> C:\Python27\lib\site-packages\spacy\data\en

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

So I am quite confused... I presume that I was unable to download the 'en' model as I do not have enough privileges to do so, but how was the linking successful?
Upon seeing this message, I tried running my Python file again ( since the terminal stated that linking was successful) but the initial error popped out again.

Has anybody encountered this problem before, or knows how to solve this error? How am I able to 'escalate' my privileges in PyCharm terminal so that I will be able to download the model?

Dittmer answered 6/10, 2018 at 9:30 Comment(0)
S
22

I don't know if it is still relevant, but I run into it too. The module was loaded well on Jupyter Notebook but not in my PyCharm. To solve it go to the interpreter of your project in PyCharm (using ctrl + alt + s). See the full path to the interpreter you are using. Then use it the terminal in such a way:

FULL_PATH_TO_PYTHON_INTERPRTER -m spacy download en

It should work now from your PyCharm.

Saga answered 20/2, 2019 at 9:50 Comment(0)
H
5

Spacy explains several ways to download a model : https://spacy.io/usage/models#download

Using python -m

# Download best-matching version of specific model for your spaCy installation
python -m spacy download en_core_web_sm

# Out-of-the-box: download best-matching default model and create shortcut link
python -m spacy download en

# Download exact model version (doesn't create shortcut link)
python -m spacy download en_core_web_sm-2.2.0 --direct

Using pip

# With external URL
pip 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

# With local file
pip install /Users/you/en_core_web_sm-2.2.0.tar.gz

Using manual download

https://spacy.io/usage/models#download-manual

Now how to download it using PyCharm ?

I tried to do it by installing an URL package Project Interpreter in a virtual environment (venv) :

https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.5/en_core_web_sm-2.2.5.tar.gz

But Pycharm failed to install the tar directly.


Solution : Finally I just add the github URL of the tar in the requirements.txt, then PyCharm will install it for you.

Add this below in requirements.txt :

# spacy
spacy
# spacy model
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.5/en_core_web_sm-2.2.5.tar.gz

You can do it for all the models on the github release page : https://github.com/explosion/spacy-models/releases/

Hamlani answered 4/12, 2019 at 13:50 Comment(0)
I
2

Actually this is what happens when you download a new spacy model, as indicated in the Spacy :

The download command will install the model via pip, place the package in your site-packages directory and create a shortcut link that lets you load the model by a custom name. The shortcut link will be the same as the model name used in spacy download.

It seems that you are installing at the system level, so try running it as "Run as Admin" or you can also try the virtualenv option. Ignore the successfull linking message, as it's just a shortcut.

You can also refer this for detailed troubleshooting guide.

Izzard answered 19/10, 2018 at 4:40 Comment(0)
L
0

go to your virtualenv then activate the venv by:

source venv/bin/activate

then when it is activated type: python -m spacy download en_core_web_sm

then desactivate the virtualenv by: deactivate

Lifelong answered 27/3, 2020 at 15:53 Comment(0)
B
0

If you are using the direct link for the model make sure to link the downloaded model files using

python -m spacy link [package name or path] [shortcut] [--force]

Usually the model files are downloaded under your-python-environment/lib/site-packages/. You should see the a folder called en once you have downloaded the tar and unpacked the model files. See this link for more info

Brood answered 28/3, 2020 at 1:52 Comment(0)
A
0

You can either setup a system variable for Python or open the CMD

C:\ CD ... Go To your directory where you have the python.exe or python interpreter installed

C:\path of the interpreter> python -m spacy download en_core_web_sm

Done , it'll install the package. what you need to make sure is the path of the interpreter, if it's common or even better take the path from the project.

Anette answered 18/9, 2020 at 10:13 Comment(0)
J
0

Also, for more info look here: https://spacy.io/usage/models#download What I found easiest to do in Pycharm was first to do:

nlp = spacy.cli.download("en_core_web_sm")

And after I did that I could just do:

nlp = spacy.load("en_core_web_sm")
Junta answered 29/12, 2023 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.