How to include en_core_web_sm in deployment?

Hi everyone!

I’m trying to deploy my classification model and the process requires spaCy, but the model download fails. I’ve tried the suggestions I saw in the community already, and none of them work for me. I can’t share my github because it’s something I’m trying for work , but I’ll add the log message I got and what I tried.

I’m seeing this error message in the log message:

ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/home/adminuser/venv/lib/python3.13/site-packages/en_core_web_sm'
Check the permissions.

[notice] A new release of pip is available: 24.0 -> 25.1.1
[notice] To update, run: python3 -m pip install --upgrade pip
Collecting en-core-web-sm==3.8.0


Please help. I’ve been debugging this for days :smiling_face_with_tear:

Since you are showing errors in your app, are you trying to modify your environment through subprocesses after your app is deployed? Or do you have all your dependencies set in requirements.txt and packages.txt? What are you environment configuration files?

Hi…So yes after I ent the text it would modify. I have all my dependencies set up in my requirements.txt and a model_utils.py file that’s trying to load the spaCy model. I didn’t have an environment configuration file. Is that required?.. I’m mainly worried about the spaCy model not being detected.

You’ll need to make sure any pip install commands are handled when the container is set up, which means putting everything you need in requirements.txt and not using a subprocess inside your app. requirements.txt is one possible environment configuration file (for things installed from PyPi). And it sounds like you do have that one? Additionally, packages.txt is something that can install Linux dependencies if you have other, non-Python things to install.

From your error message, it seems you’re facing a permission issue when trying to install the en_core_web_sm model. This usually happens when you’re attempting to install in a restricted directory. Try installing it with the --user flag so the installation happens at the user level, like this: python -m spacy download en_core_web_sm --user. If you have sudo access, you can also try using sudo. Additionally, make sure your virtual environment is properly activated and you’re working in a directory where you have write permissions. Hopefully, this will help.