4

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

7
  • 1
    probabily also the opencv contrib module should be headless: "opencv-contrib-python-headless" Commented May 24, 2022 at 15:03
  • 1
    please ONLY use opencv-contrib-python-headless, not both Commented May 24, 2022 at 15:42
  • @berak just to clarify, are you saying to get rid of opencv-python-headless and just have opencv-contrib-python-headless as the opencv install? Commented May 24, 2022 at 16:11
  • yes, exactly !!! (it already contains opencv-python) Commented May 24, 2022 at 16:13
  • @berak I have updated my question with the requirements I am using now. I have tried it with the new list and it is still giving me the same error. Commented May 24, 2022 at 16:58

1 Answer 1

9

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
Sign up to request clarification or add additional context in comments.

1 Comment

I'm hoping these work on amazonlinux:2018.03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.