R
Railway•10mo ago
Induane

Deploy issue with Python PIL/Pillow and libwebp.so.7 not found

I'm running into what seems like a fairly simple deploy issue:
from faerymarket.utils import image
File "/opt/venv/lib/python3.11/site-packages/faerymarket/utils/image.py", line 9, in <module>
from PIL import Image as PILImage
File "/opt/venv/lib/python3.11/site-packages/PIL/Image.py", line 114, in <module>
from . import _imaging as core
ImportError: libwebp.so.7: cannot open shared object file: No such file or directory
from faerymarket.utils import image
File "/opt/venv/lib/python3.11/site-packages/faerymarket/utils/image.py", line 9, in <module>
from PIL import Image as PILImage
File "/opt/venv/lib/python3.11/site-packages/PIL/Image.py", line 114, in <module>
from . import _imaging as core
ImportError: libwebp.so.7: cannot open shared object file: No such file or directory
In my earlier attempts, I simply couldn't get the package to build, so I updated the railway.json file to include the build dependencies. Here is my railway.json file:
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"phases": {
"setup": {
"aptPkgs": ["...", "libtiff5-dev" , "libjpeg-dev", "libopenjp2-7-dev", "zlib1g-dev", "libfreetype6-dev", "liblcms2-dev", "libwebp-dev", "libharfbuzz-dev", "libfribidi-dev", "libxcb1-dev"]
}
}
}
},
"deploy": {
"numReplicas": 1,
"startCommand": "python src/faerymarket/manage.py migrate && python src/faerymarket/manage.py collectstatic --noinput --clear && bin/uwsgi --ini=src/faerymarket/api.ini",
"healthcheckPath": "health/",
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"phases": {
"setup": {
"aptPkgs": ["...", "libtiff5-dev" , "libjpeg-dev", "libopenjp2-7-dev", "zlib1g-dev", "libfreetype6-dev", "liblcms2-dev", "libwebp-dev", "libharfbuzz-dev", "libfribidi-dev", "libxcb1-dev"]
}
}
}
},
"deploy": {
"numReplicas": 1,
"startCommand": "python src/faerymarket/manage.py migrate && python src/faerymarket/manage.py collectstatic --noinput --clear && bin/uwsgi --ini=src/faerymarket/api.ini",
"healthcheckPath": "health/",
"sleepApplication": false,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
The custom build command is:
python -m pip install .
python -m pip install .
This all works fine with the exception of the inability to import the image library. My best guess, because I'm only partway though a lot of the docs, is that perhaps the setup phase packages aren't included in the final image layer? Does anyone have any ideas I could try?
9 Replies
Percy
Percy•10mo ago
Project ID: N/A
Induane
InduaneOP•10mo ago
Project ID: 26158cd2-ea48-4b82-815a-a7bfdc2a83bd
Brody
Brody•10mo ago
you have gotten extremely far, and I think you are correct with your assumption on why it doesn't work, those packages are getting installed but aren't included in the final image, or maybe the library paths aren't being updated, something along those lines. solution being, use a Dockerfile based build and install all those same packages
Induane
InduaneOP•10mo ago
Yea - I can switch it to docker if I have to I suppose. It's an OCI container at the end either way
Brody
Brody•10mo ago
Dockerfile also gives you far more control
Induane
InduaneOP•10mo ago
The nixpack stuff seemed fun though, and also to be the default. Usually I try to go with as much default as possible as it's often the happy path. But I can setup a decent multistage dockerfile and call it a day
Brody
Brody•10mo ago
Railway will always support Dockerfiles, after all, nixpacks is literally putting together a dockerfile
Induane
InduaneOP•10mo ago
That's cool - I didn't know it just built a dockerfile under the hood. I assumed it was some bespoke custom OCI complaint container generator 😄
Brody
Brody•10mo ago
yep! so if you're comfortable with Dockerfiles, writing one yourself is going to give you far more control
Want results from more Discord servers?
Add your server