1

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.
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Dani S
  • 15
  • 2
  • 6
  • You need to download the model first. https://github.com/explosion/spacy-models . `python -m spacy download de_core_news_sm` – Equinox Oct 08 '20 at 18:53
  • Thnk you for your answer. Where do I have to put the model after downloading it? And which files do I have to download? – Dani S Oct 09 '20 at 16:10

2 Answers2

3

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
bhucho
  • 3,903
  • 3
  • 16
  • 34
  • But that is exactly what I did. first install spacy with `pip install -U spacy` and then download the package with `python -m spacy download de_core_news_sm`. But that will lead to the error. So I do not get the problem. I do not do anything in google colab but in jupyter notebook. Do I have to insert the install and download cammand in the console? – Dani S Oct 09 '20 at 09:30
  • are you using python3, then write python3 and pip3 inplace of python and pip – bhucho Oct 09 '20 at 10:47
  • try creating a virtual env then putting spacy in it after activating it, updated the answer to show how to add virtual env – bhucho Oct 09 '20 at 10:48
  • With `import sys print(sys.version)` i get `3.6.10 |Anaconda, Inc.` If I use pip3 it throws a error called: `SyntaxError: invalid syntax`. I will try to add virtual environment – Dani S Oct 09 '20 at 12:12
  • what os are you on linux, win or mac? – bhucho Oct 09 '20 at 12:49
  • if you are using conda, try using `conda install -c conda-forge spacy` to install spacy(see here https://anaconda.org/conda-forge/spacy), the use this earlier command `python -m spacy download de_core_news_sm` – bhucho Oct 09 '20 at 12:57
  • I am using win. I tried it with `conda install -c conda-forge spacy` in the anaconda prompt. I think the error is the downloading of the package (for example `de_core_news_sm`) in my `dir: "C:\Users\danis\.conda\envs\python36\Lib\site-packages\spacy"` I cannot find the folder `data`, where the package should be (compared to this article: https://github.com/explosion/spaCy/issues/3592). – Dani S Oct 09 '20 at 14:19
  • try some other language package this one is for english python -m spacy download en_core_web_sm to check https://spacy.io/models/en – bhucho Oct 09 '20 at 16:29
  • Ends in the same error on the same part... My Anaconda Prompt shows `You can now load the model via spacy.load('en_core_web_sm')` after installing the package in Anaconda Prompt with `python -m spacy download en_core_web_sm`. But if I want to load the model in Jupyter Notebook it does not work. – Dani S Oct 09 '20 at 16:45
  • Error: `OSError Traceback (most recent call last) in ----> 1 nlp = spacy.load("de_core_news_md") 2 #nlp = spacy.load("en_core_web_sm") 3 #spacy.util.get_data_path ~\.conda\envs\python36\lib\site-packages\spacy\__init__.py in load(name, **overrides) ~\.conda\envs\python36\lib\site-packages\spacy\util.py in load_model(name, **overrides) OSError: [E049] Can't find spaCy data directory: 'None'. Check your installation and permissions, or use spacy.util.set_data_path to customise the location if necessary. ` – Dani S Oct 09 '20 at 16:48
  • https://stackoverflow.com/questions/47295316/importerror-no-module-named-spacy-en, try this one basically try to load spacy in anaconda prompt – bhucho Oct 09 '20 at 16:57
  • I tried it and it is still not working. The error by calling `nlp = spacy.load('de_core_news_sm')` is `AttributeError: module 'spacy' has no attribute 'load'` Do you know the code, that I can deinstall spacy completely. After that I would try to reinstall it. – Dani S Oct 10 '20 at 09:24
  • I do have two different Anaconda-paths, on both there is spacy installed, but with different data in it. Maybe I made something wrong by installing it? – Dani S Oct 10 '20 at 09:33
  • try `pip list` if you find your `de-core-news-sm` in it, then uninstall it `pip uninstall de-core-news-sm` – bhucho Oct 10 '20 at 10:08
  • see this to delete module https://pip.pypa.io/en/stable/reference/pip_uninstall/ – bhucho Oct 10 '20 at 10:12
  • In `pip list` I find `de-core-news-sm`. I try to uninstall it, but it loads for 1 hour now. I don't thin, that this is normal. If I do have `de-core-news-sm` in `pip list`, why does the code `spacy.load("de-core-news-sm")` not work? – Dani S Oct 13 '20 at 09:02
  • when you do import spacy in command line, is there any error, check your version of spacy, then check its model compatibility from here https://github.com/explosion/spacy-models/blob/master/compatibility.json – bhucho Oct 13 '20 at 10:24
  • I would suggest trying from the beggining or put an issue here https://github.com/explosion/spaCy, there is one of the user named `ines`, you can expect quick reply from her – bhucho Oct 13 '20 at 10:26
  • Spacy version 2.3.2 and "de_core_news_sm": ["2.3.0"], so that should work. Yes I want to try it from the beginning, but deinstallation does not work. I used `pip uninstall de-core-news-sm` and `pip uninstall spacy`. It doesn't work – Dani S Oct 13 '20 at 18:24
  • If I make `import spacy`, the error is `C:\Users\danis\.conda\envs\python36\lib\site-packages\cupy\_environment.py:148: UserWarning: CUDA path could not be detected. Set CUDA_PATH environment variable if CuPy fails to load. 'CUDA path could not be detected.'` How can I solve this problem? Cuda is the GPU-Version, but I don't want that... – Dani S Oct 13 '20 at 18:52
0

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

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 21 '22 at 21:32