I have a Docker image I am building to run on AWS Lambda.
One of the dependencies is opencv, but I am using the headless version.
My requirements file is:
absl-py==1.0.0
attrs==21.4.0
cycler==0.11.0
flatbuffers==2.0
fonttools==4.33.3
imageio==2.19.2
jmespath==1.0.0
kiwisolver==1.4.2
matplotlib==3.5.2
mediapipe==0.8.10
networkx==2.8.1
numpy==1.22.3
onnxruntime==1.11.1
opencv-contrib-python-headless==4.5.5.64
packaging==21.3
Pillow==9.1.1
protobuf==3.20.1
pyparsing==3.0.9
python-dateutil==2.8.2
PyWavelets==1.3.0
scikit-image==0.19.2
scipy==1.8.1
six==1.16.0
tifffile==2022.5.4
urllib3==1.26.9
And my Dockerfile is:
FROM public.ecr.aws/lambda/python:3.8
COPY requirements.txt .
RUN pip install -r requirements.txt && rm requirements.txt
COPY lambda_function.py ./
COPY remove.py ./
COPY detect.py ./
COPY u2net.onnx ./
CMD [ "lambda_function.lambda_handler" ]
The exact error I am getting in Lambda is:
{
"errorMessage": "Unable to import module 'lambda_function': libGL.so.1: cannot open shared object file: No such file or directory",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
}
I have tried researching what could be happening but have come up empty handed. Why would I be getting this error when using the headless version? Thank you
I needed to update my container repositories and install a dependency, libgl1-mesa-glx
:
RUN apt update
# Dependency for opencv-python (cv2). `import cv2` raises ImportError: libGL.so.1: cannot open shared object file: No such file or directory
# Solution from https://askubuntu.com/a/1015744
RUN apt install -y libgl1-mesa-glx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With