How to place Spacy en_core_web_md model in Python package

Viewed 2840

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?

1 Answers

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')
Related