Spacy And Spacy Models In Setup.py
Solution 1:
You can use pip's recent support for PEP 508 URL requirements:
install_requires=[
'spacy',
'en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz',
],
Note that this requires you to build your project with up-to-date versions of setuptools and wheel (at least v0.32.0 for wheel; not sure about setuptools), and your users will only be able to install your project if they're using at least version 18.1 of pip.
More importantly, though, this is not a viable solution if you intend to distribute your package on PyPI; quoting pip's release notes:
As a security measure, pip will raise an exception when installing packages from PyPI if those packages depend on packages not also hosted on PyPI. In the future, PyPI will block uploading packages with such external URL dependencies directly.
Solution 2:
Here is my workaround for a PyPi-installable package (edited slightly for clarity):
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')
It's cumbersome, but at least it works without having to involve the user. I'm trying to convince the spaCy team to package the most important model files for PyPi.
Solution 3:
Not sure if this works for you, but in setup.py
you might try:
os.system('python -m spacy download en')
after calling setuptools.setup(...)
edit:
According to spaCy docs, it looks like you can now add SpaCy models to your requirements.txt via url as well. You should then be able to import the model as a module where it is required:
importen_core_web_smnlp= en_core_web_sm.load()
Post a Comment for "Spacy And Spacy Models In Setup.py"