opencv_aws_lambda icon indicating copy to clipboard operation
opencv_aws_lambda copied to clipboard

libGL.so.1: cannot open shared object file

Open jongsun-yun-nuvi opened this issue 4 years ago • 11 comments

there is import error when I run 'import cv2' { "errorMessage": "Unable to import module 'lambda_function': libGL.so.1: cannot open shared object file: No such file or directory", "errorType": "Runtime.ImportModuleError" } START RequestId: fa84da1a-ffa1-46ac-80e1-da354fb38d2b Version: $LATEST [ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': libGL.so.1: cannot open shared object file: No such file or directoryEND RequestId: fa84da1a-ffa1-46ac-80e1-da354fb38d2b REPORT RequestId: fa84da1a-ffa1-46ac-80e1-da354fb38d2b Duration: 1.74 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 60 MB Init Duration: 168.43 ms

jongsun-yun-nuvi avatar Aug 21 '20 02:08 jongsun-yun-nuvi

@jongsun-nuvi Make sure your Lambda function and all Lambda layers are configured for the same Python runtime version.

aldhalaan avatar Aug 22 '20 16:08 aldhalaan

Running into the same issue, and @aldhalaan, I triple-checked that they are configured for the same Python runtime version. Did not fix the issue.

jamesshapiro avatar Dec 19 '20 03:12 jamesshapiro

@jamesshapiro What version of python were you using 3.7 or 3.8? Did you manage to solve this issue?

pacarvalho avatar Jan 12 '21 18:01 pacarvalho

@pacarvalho Either 3.8 or 3.6, I'm pretty sure it was 3.8 though. Finally managed to install cv2 as a Lambda layer by following the instructions in the top answer on this StackOverflow post: https://stackoverflow.com/questions/64016819/cant-use-opencv-python-in-aws-lambda

I sort of wish that the iandow tutorial were taken down, it was a complete dead-end for me.

jamesshapiro avatar Jan 12 '21 18:01 jamesshapiro

@jamesshapiro Thank you for the link!

I believe the issue is with the AmazonLinux version and a change in the version that is installed via yum with the Dockefile below it seems to import cv2 correctly.

FROM amazonlinux:1

WORKDIR /
RUN yum update -y

# Install Python 3.7
RUN yum install gcc openssl-devel wget tar -y
RUN wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
RUN tar -xzvf Python-3.7.9.tgz
WORKDIR /Python-3.7.9
RUN ./configure --enable-optimizations
RUN make install

# Install Python packages
RUN mkdir /packages
RUN echo "opencv-python" >> /packages/requirements.txt
RUN mkdir -p /packages/opencv-python-3.7/python/lib/python3.7/site-packages
RUN pip3.7 install -r /packages/requirements.txt -t /packages/opencv-python-3.7/python/lib/python3.7/site-packages

pacarvalho avatar Jan 12 '21 19:01 pacarvalho

@pacarvalho I've tried the above with amazonlinux:1, albeit for python 3.8, but it still fails when running with sam local invoke

nielswart avatar Jul 09 '21 13:07 nielswart

@nielswart I recommend following Marcin's advice here: https://stackoverflow.com/questions/64016819/cant-use-opencv-python-in-aws-lambda . I found the instructions in this repo completely useless.

jamesshapiro avatar Jul 09 '21 15:07 jamesshapiro

Thanks @jamesshapiro I'm giving that a try!!

nielswart avatar Jul 09 '21 15:07 nielswart

I'd like to give an update on what I did to work around this issue:

At first I updated the Dockerfile in this repository to also include the steps outlined in https://stackoverflow.com/questions/64016819/cant-use-opencv-python-in-aws-lambda.

When running with sam local I encoutered a different issue that libpng15-c2ffaf3d.so.15.13.0 could not be found. This was however present in the layer and I could see the file from within my python lambda handler function and it was on the python path 😕

While searching for a solution I realised that this whole approach is backwards and that using the opencv-python-headless package was the answer. Since we don't have hardware acceleration in the AWS Lambda there's no reason to include the libgl and related X11 libraries.

I thus got rid of the layer and build my lambda with the sam build --use-container flag and it works.

nielswart avatar Jul 16 '21 13:07 nielswart

I'd like to give an update on what I did to work around this issue:

At first I updated the Dockerfile in this repository to also include the steps outlined in https://stackoverflow.com/questions/64016819/cant-use-opencv-python-in-aws-lambda.

When running with sam local I encoutered a different issue that libpng15-c2ffaf3d.so.15.13.0 could not be found. This was however present in the layer and I could see the file from within my python lambda handler function and it was on the python path 😕

While searching for a solution I realised that this whole approach is backwards and that using the opencv-python-headless package was the answer. Since we don't have hardware acceleration in the AWS Lambda there's no reason to include the libgl and related X11 libraries.

I thus got rid of the layer and build my lambda with the sam build --use-container flag and it works.

You should consider making a StackOverflow Q&A post about this for visibility. I'm sure others building with SAM would find it helpful.

jamesshapiro avatar Jul 16 '21 14:07 jamesshapiro

I'd like to give an update on what I did to work around this issue:

At first I updated the Dockerfile in this repository to also include the steps outlined in https://stackoverflow.com/questions/64016819/cant-use-opencv-python-in-aws-lambda.

When running with sam local I encoutered a different issue that libpng15-c2ffaf3d.so.15.13.0 could not be found. This was however present in the layer and I could see the file from within my python lambda handler function and it was on the python path 😕

While searching for a solution I realised that this whole approach is backwards and that using the opencv-python-headless package was the answer. Since we don't have hardware acceleration in the AWS Lambda there's no reason to include the libgl and related X11 libraries.

I thus got rid of the layer and build my lambda with the sam build --use-container flag and it works.

in long long long long time i find it, and finally work for me, Thanks!

andersonpda avatar Mar 22 '23 16:03 andersonpda