Skip to content

Atualizar Dockerfile / pillow dependencias #985

@robertatakenaka

Description

@robertatakenaka

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:392 in _get_bytes()
  • self._image_object.convert("RGB").save(image_file, format)

Root Cause

  1. Pillow version: Current packtools uses Pillow 10.1.0 (4.11.8) / 9.1.0 (2.9.5)
  2. Critical change: Since Pillow 6.0.0 (2019), .convert("RGB") automatically uses color management
  3. Missing dependency: Alpine Linux Docker build lacks lcms2-dev (build-time) and lcms2 (runtime)
  4. Result: Pillow compiles without _imagingcms module, 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions