Spacy Load model in docker

Viewed 2016

I want to run a spacy text manipulation in a docker container.

My project is simple:

FROM python:3-onbuild

RUN python -m spacy download en_core_web_sm

CMD  ["python3", "TextAnalyzerLaunch.py"]

on build I see the model successfully download.

However,on docker run sp = spacy.load('en') does not find the model

So I tried to be smart (well hacky):

try:
    sp = spacy.load('en')
except:
    log.getLogger().info("Loading spacy model")
    subprocess.call(['python', '-m', "spacy", "download", "en_core_web_sm"])
    sp = spacy.load('en')
    pass

Again, I see it loads successfully, but still get the following error

Can't find model 'en'. It doesn't seem to be a shortcut link .....

NOTE: without docker, my tool runs just fine

1 Answers

Oh, well that was simple actually:

While p = spacy.load('en') worked fine in pycharm, I need the full p = spacy.load('en_core_web_sm') in a docker container

Related