October 19, 2024

You might have an error like below when you call opencv-python using import cv2.

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

or

ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory

The error occurs when cv2 cannot find the native libraries it depends on.

This would resolve the error.

RUN apt-get install libopencv-dev -y 

or

RUN apt-get install libgl1-mesa-dev -y

Dockerfile should be like below

FROM python:3.8.10-slim-buster

COPY ./ ./

RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install libopencv-dev -y 

RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN pip install opencv-python