-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Labels
Description
Pillow _imagingcms ImportError in Alpine Linux Docker containers
relacionado com scieloorg/opac-airflow#474
Summary
The packtools Docker image fails when processing images that require RGB conversion due to missing _imagingcms module in Pillow. This affects any functionality that calls Image.convert("RGB") in Alpine Linux environments.
Error Details
ImportError: cannot import name '_imagingcms' from 'PIL'
(/usr/local/lib/python3.11/site-packages/PIL/__init__.py)
Stack trace location:
packtools/utils.py:392in_get_bytes()self._image_object.convert("RGB").save(image_file, format)
Root Cause
- Pillow version: Current packtools uses Pillow 10.1.0 (4.11.8) / 9.1.0 (2.9.5)
- Critical change: Since Pillow 6.0.0 (2019),
.convert("RGB")automatically uses color management - Missing dependency: Alpine Linux Docker build lacks
lcms2-dev(build-time) andlcms2(runtime) - Result: Pillow compiles without
_imagingcmsmodule, causing runtime failures
Environment
- Docker base:
python:3.11-alpine/python:3.7-alpine - Packtools versions: 2.9.5, 4.11.8 (likely all versions)
- Affected operations: Image optimization, PNG/JPEG conversion
Impact
- ❌ Rancher/Kubernetes: Fails (minimal Alpine images)
- ✅ Docker Desktop macOS: Works (lcms2 often pre-installed)
- ❌ Production Alpine environments: Fails
Reproduction
# In Alpine container without lcms2
python -c "
from PIL import Image
import io
img = Image.new('RGBA', (100, 100), (255, 0, 0, 128))
img.convert('RGB') # Triggers _imagingcms import
"Proposed Solution
Add lcms2 dependencies to Dockerfile:
Build dependencies (temporary):
lcms2-dev,freetype-dev,openjpeg-dev,tiff-dev,libpng-dev,zlib-dev
Runtime dependencies (permanent):
lcms2,freetype,openjpeg,libpng,tiff,zlib
Workaround
Users can temporarily patch by adding lcms2 to their own Dockerfiles, but this should be fixed upstream to ensure consistent behavior across environments.
Related
- Similar issue affects other Alpine-based Python applications using modern Pillow versions
- Color management is essential for scientific image processing (SciELO's use case)