7

I am building a python package and I am using Spacy library and Spacy model en_core_web_md. It can't be installed using pip. You can install it like this

python -m spacy download en_core_web_md

I have place en_core_web_md folder in my Python package.

  • simple_eda

    • init.py
    • simple_eda.py
    • en_core_web_md
  • tests

  • setup.py

  • README.md

  • LICENSE

I can install package successfully but when I import, it gives me this error.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/shahid/anaconda3/envs/eda_test_6/lib/python3.5/site-packages/simple_nlp/__init__.py", line 1, in <module>
    from simple_nlp.simple_nlp import SimpleNLP
  File "/home/shahid/anaconda3/envs/eda_test_6/lib/python3.5/site-packages/simple_nlp/simple_nlp.py", line 22, in <module>
    nlp = spacy.load("en_core_web_md")
  File "/home/shahid/anaconda3/envs/eda_test_6/lib/python3.5/site-packages/spacy/__init__.py", line 30, in load
    return util.load_model(name, **overrides)
  File "/home/shahid/anaconda3/envs/eda_test_6/lib/python3.5/site-packages/spacy/util.py", line 175, in load_model
    raise IOError(Errors.E050.format(name=name))
OSError: [E050] Can't find model 'en_core_web_md'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory.

Where should I place the folder, or should I add a link to that folder in setup.py file?

halfer
  • 19,824
  • 17
  • 99
  • 186
shahid hamdam
  • 751
  • 1
  • 10
  • 24
  • How did you import it? Try this one and see if it works or not? 'Import spacy Nlp= spacy.laod('en_core_web_md')' Also I had the same error with en_core_web_sm, I used direct link and pip to solve it and it workd, with this command: ' pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.1.0/en-core-web-sm-2.1.0.tar.gz'. There is en-core-web-md in this link too so I think it's helpful to try to download it manually and install it with pip – A.mh Jul 04 '20 at 12:46
  • How do you package `en_core_web_md`? What is in your `setup.py`? – phd Jul 04 '20 at 16:24
  • @phd as you can see I have places en_core_web_md folder in my simple_nlp folder. and I import it like nlp = spacy.load("en_core_web_md"). A.mh this answers your question too. taha I want to publish my package on Pypi, so the solution is not reliable. – shahid hamdam Jul 04 '20 at 16:46
  • @taha please check my above comment – shahid hamdam Jul 04 '20 at 16:46
  • @A.mh you too please. – shahid hamdam Jul 04 '20 at 16:46

1 Answers1

15

This solved my issue.

try:
    nlp = spacy.load('en')
except OSError:
    print('Downloading language model for the spaCy POS tagger\n'
        "(don't worry, this will only happen once)", file=stderr)
    from spacy.cli import download
    download('en')
    nlp = spacy.load('en')
shahid hamdam
  • 751
  • 1
  • 10
  • 24
  • I solved this issue base on your solution and this link https://github.com/explosion/spaCy/issues/4577 – han shih Sep 26 '22 at 06:56