Cannot deploy Spacy / Python modules on Digital Ocean functions

Viewed 33

I am quite new to serverless functions and now I have been trying to deploy Spacy to Digital Ocean functions but without success. The function is very simple (basically just to see if I can import Spacy). I have structured the project according to https://docs.digitalocean.com/products/functions/how-to/structure-projects/ and it works locally and doctl serverless deploy . works without errors. However, it seems like dependencies are not installed, or at least Spacy cannot be found.

main.py

import spacy

def main(arg):
      return {"body": 'test'}

requirements.txt

blis==0.7.8
catalogue==2.0.8
certifi==2022.6.15
charset-normalizer==2.1.1
click==8.1.3
cymem==2.0.6
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.4.0/en_core_web_sm-3.4.0-py3-none-any.whl
idna==3.3
Jinja2==3.1.2
langcodes==3.3.0
MarkupSafe==2.1.1
murmurhash==1.0.8
numpy==1.23.2
packaging==21.3
pathy==0.6.2
pkg_resources==0.0.0
preshed==3.0.7
pydantic==1.9.2
pyparsing==3.0.9
requests==2.28.1
smart-open==5.2.1
spacy==3.4.1
spacy-legacy==3.0.10
spacy-loggers==1.0.3
srsly==2.4.4
thinc==8.1.0
tqdm==4.64.0
typer==0.4.2
typing_extensions==4.3.0
urllib3==1.26.12
wasabi==0.10.1

Errors:

stderr: Invalid action: No module named 'spacy'
stderr: The action did not initialize or run as expected. Log data might be missing.

Any pointers or suggestions are appreciated. Thanks!

1 Answers

You have the below line in the requirements.txt file:

pkg_resources==0.0.0

This means you use pip freeze for collecting the necessary packages as your project requirements. Let's ignore the fact that this method is not a good method for doing this job, but this line I mentioned above disrupts the installation of the packages you need in the virtual environment and causes its subsequent packages to not be installed in a certain file, and that is why the error of the absence of this package delete this line from the requirements file and try again.

Related