Install SpaCy in a Jupyter Notebook

10k views Asked by At

I try to install SpaCy for lemmatization, but it won't work...

First I install spacy:

pip install -U spacy

Which leads to this results:

Requirement already satisfied, skipping upgrade: murmurhash<1.1.0,>=0.28.0 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (1.0.2)
Requirement already satisfied, skipping upgrade: srsly<1.1.0,>=1.0.2 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (1.0.2)
Requirement already satisfied, skipping upgrade: thinc==7.4.1 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (7.4.1)
Requirement already satisfied, skipping upgrade: cymem<2.1.0,>=2.0.2 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (2.0.3)
Requirement already satisfied, skipping upgrade: wasabi<1.1.0,>=0.4.0 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (0.8.0)
Requirement already satisfied, skipping upgrade: catalogue<1.1.0,>=0.0.7 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (1.0.0)
Requirement already satisfied, skipping upgrade: requests<3.0.0,>=2.13.0 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (2.23.0)
Requirement already satisfied, skipping upgrade: tqdm<5.0.0,>=4.38.0 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (4.50.2)
Requirement already satisfied, skipping upgrade: blis<0.5.0,>=0.4.0 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (0.4.1)
Requirement already satisfied, skipping upgrade: numpy>=1.15.0 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (1.18.1)
Requirement already satisfied, skipping upgrade: setuptools in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (46.1.3.post20200330)
Requirement already satisfied, skipping upgrade: plac<1.2.0,>=0.9.6 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (1.1.3)
Requirement already satisfied, skipping upgrade: preshed<3.1.0,>=3.0.2 in c:\users\danis\.conda\envs\python36\lib\site-packages (from spacy) (3.0.2)
Requirement already satisfied, skipping upgrade: importlib-metadata>=0.20; python_version < "3.8" in c:\users\danis\.conda\envs\python36\lib\site-packages (from catalogue<1.1.0,>=0.0.7->spacy) (2.0.0)
Requirement already satisfied, skipping upgrade: idna<3,>=2.5 in c:\users\danis\.conda\envs\python36\lib\site-packages (from requests<3.0.0,>=2.13.0->spacy) (2.9)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in c:\users\danis\.conda\envs\python36\lib\site-packages (from requests<3.0.0,>=2.13.0->spacy) (2020.6.20)
Requirement already satisfied, skipping upgrade: chardet<4,>=3.0.2 in c:\users\danis\.conda\envs\python36\lib\site-packages (from requests<3.0.0,>=2.13.0->spacy) (3.0.4)
Requirement already satisfied, skipping upgrade: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\danis\.conda\envs\python36\lib\site-packages (from requests<3.0.0,>=2.13.0->spacy) (1.25.8)
Requirement already satisfied, skipping upgrade: zipp>=0.5 in c:\users\danis\.conda\envs\python36\lib\site-packages (from importlib-metadata>=0.20; python_version < "3.8"->catalogue<1.1.0,>=0.0.7->spacy) (2.2.0)

Then I try to import spacy:

import spacy

which works fine, no error occur. And then I want to load a data package:

nlp = spacy.load('de_core_news_sm')

Here the error occur:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-10-0fb7762ce64d> in <module>
----> 1 nlp = spacy.load('de_core_news_sm')

~\.conda\envs\python36\lib\site-packages\spacy\__init__.py in load(name, **overrides)
     28     if depr_path not in (True, False, None):
     29         warnings.warn(Warnings.W001.format(path=depr_path), DeprecationWarning)
---> 30     return util.load_model(name, **overrides)
     31 
     32 

~\.conda\envs\python36\lib\site-packages\spacy\util.py in load_model(name, **overrides)
    173     elif hasattr(name, "exists"):  # Path or Path-like to model data
    174         return load_model_from_path(name, **overrides)
--> 175     raise IOError(Errors.E050.format(name=name))
    176 
    177 

OSError: [E050] Can't find model 'de_core_news_sm'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.
2

There are 2 answers

20
bhucho On

In order to load the model you need to download it first, if you are doing it on your local machine.(not on google colab). So after

pip install -U spacy

you need to download using

python -m spacy download de_core_news_sm

Then,

nlp = spacy.load('de_core_news_sm') 

Google Colaboratory

In case of trying it in google colab,

pip install -U spacy
import spacy.cli
spacy.cli.download("de_core_news_sm")

You can also add virtual environment then use spacy after activating in virtual environment.

python3 -m venv <name_of_virtualenv>
# to activate 
source /pathtovirenc/<name_of_virtualenv>/bin/activate

#then use the above commands
pip3 install -U spacy
python3 -m spacy download de_core_news_sm
1
Vishnu Prasad. S. 102 CS On

If Ur Installin this in Ananconda or jupyter this method isn't gonna work . Search Spacy And in the 1st link Spacy.io-> click on usage -. select Conda for jupyter notebook -> Thn u will get the right command to run