Disable rembg to fix build - numpy version conflict

rembg>=2.0.70 has an incompatible dependency chain:
- rembg requires scikit-image>=0.26.0
- scikit-image 0.26+ pulls in numpy 2.x
- opencv-python-headless 4.9.0.80 was compiled for numpy 1.x
- Runtime crash: "numpy.core.multiarray failed to import"

Fix: Revert to known-working numpy<2 stack:
- numpy<2.0.0 (explicit pin)
- Pillow 10.x (compatible with numpy 1.x)
- torch 2.1.2 / torchvision 0.16.2 (numpy 1.x compatible)
- Remove rembg and onnxruntime

Background removal endpoints will return 500 with "rembg not installed"
message (code already handles this gracefully).

To re-enable rembg in future: update opencv-python-headless to 4.10+
which supports numpy 2.x.

https://claude.ai/code/session_01MYpjNQXD1fZE4gCweGU4QQ
This commit is contained in:
Claude
2026-01-27 17:55:54 +00:00
parent 62ad349a83
commit 41598722f1
2 changed files with 13 additions and 14 deletions
+1 -4
View File
@@ -2,7 +2,7 @@ FROM python:3.11-slim
WORKDIR /app
# Install system dependencies for OpenCV, rembg, SAM, and image processing
# Install system dependencies for OpenCV, SAM, and image processing
RUN apt-get update && apt-get install -y \
libgl1 \
libglib2.0-0 \
@@ -20,9 +20,6 @@ COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Pre-download rembg model (u2net) to avoid first-run delay
RUN python -c "from rembg import remove; print('rembg model downloaded')" || true
# Copy application
COPY . .
+12 -10
View File
@@ -1,8 +1,8 @@
fastapi==0.109.0
uvicorn[standard]==0.27.0
python-multipart==0.0.6
Pillow>=12.1.0,<13.0.0
# numpy version will be resolved by pip based on torch/rembg requirements
Pillow>=10.0.0,<11.0.0
numpy<2.0.0
sqlalchemy==2.0.25
python-jose[cryptography]==3.3.0
passlib[bcrypt]==1.7.4
@@ -13,13 +13,15 @@ pydantic==2.5.3
pydantic-settings==2.1.0
email-validator==2.1.0
opencv-python-headless==4.9.0.80
# scikit-image removed - let pip resolve it automatically via rembg dependency
# rembg for background removal with BiRefNet models (state-of-the-art)
# Using latest onnxruntime (1.17+ fixed executable stack issues)
onnxruntime>=1.17.0
rembg>=2.0.70
# SAM (Segment Anything) for smart object selection - runs locally, no API needed
# Using torch 2.4+ for numpy 2.x compatibility (required by scikit-image 0.26+)
torch>=2.4.0
torchvision>=0.19.0
torch==2.1.2
torchvision==0.16.2
segment-anything @ git+https://github.com/facebookresearch/segment-anything.git
# NOTE: rembg (background removal) disabled due to dependency conflicts
# rembg>=2.0.70 requires:
# - scikit-image>=0.26.0 which requires numpy>=2.0
# - Pillow>=12.1.0
# But opencv-python-headless 4.9.0.80 requires numpy<2.0
# To enable rembg, need to update opencv-python-headless to 4.10+ (numpy 2.x compatible)
# and update all dependent packages accordingly