最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Error importing cv2 "ModuleNotFoundError: No module named 'cv2' in Docker image - Stack Overfl

programmeradmin3浏览0评论

I tried to build docker image of python application with this dockerfile:

FROM python:3.10-slim

WORKDIR /app

# Install system dependencies Git
RUN apt-get update && apt-get install -y --no-install-recommends git curl unzip \
    && rm -rf /var/lib/apt/lists/* \
    && curl ".zip" -o "awscliv2.zip" \
    && unzip awscliv2.zip \
    && ./aws/install \
    && rm -rf aws awscliv2.zip

# Copy and install Python dependencies
COPY sai/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt \
    && pip uninstall -y opencv-python \
    && pip install --no-cache-dir opencv-python-headless==4.11.0.86 \
    && rm -rf /root/.cache/pip

# Copy only necessary libraries
COPY libs/python /app/libs/python  
RUN pip install --no-cache-dir /app/libs/python/s3_py \
    && pip install --no-cache-dir /app/libs/python/kafka_py

I do these particular line because i notice in my requirements there's an AI model such as Real-ESRGAN and several other things listed opencv-python as their dependencies in their metadata.

&& pip uninstall -y opencv-python \
&& pip install --no-cache-dir opencv-python-headless==4.11.0.86 \

However, eventhough i've uninstalled the opencv-python first, and proceed to install the headless version, the module cv2 was nowhere to be found, even after i list my packages using

python -c "import pkgutil; print([m.name for m in pkgutil.iter_modules()])".

is there any workaround to solve this?

发布评论

评论列表(0)

  1. 暂无评论