I'm creating a lambda layer from a dockerfile that installs python packages to a directory and zips the result.
FROM amazonlinux
WORKDIR /
RUN yum update -y
# Install Python 3.7
RUN yum install python3 zip -y
RUN pip3.7 install --upgrade pip
# 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
# Create zip files for Lambda Layer deployment
WORKDIR /packages/opencv-python-3.7/
RUN zip -r9 /packages/cv2-python37.zip .
WORKDIR /packages/
RUN rm -rf /packages/opencv-python-3.7/
For this Dockerfile I can successfully deploy.
Now I want to add more libraries¹ but despite successful docker build and upload, there is an error when executing the lambda function (numpy not found).
I would like an easier way to debug this than changing the Docker file, building, extracting and uploading the zip file and pressing 'test' in the AWS management console.
I've tried to run the docker container locally and just install the packages there and see if everything can be imported in a python shell but I cannot even recreate the original this way:
bash-4.2# pip3.7 install opencv-python
Collecting opencv-python
Using cached opencv_python-4.4.0.42-cp37-cp37m-manylinux2014_x86_64.whl (49.4 MB)
Collecting numpy>=1.14.5
Using cached numpy-1.19.1-cp37-cp37m-manylinux2010_x86_64.whl (14.5 MB)
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.19.1 opencv-python-4.4.0.42
bash-4.2# python3.7
Python 3.7.8 (default, Jul 24 2020, 20:26:49)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib64/python3.7/site-packages/cv2/__init__.py", line 5, in <module>
from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
How can I figure out the right dependencies on my local machine?
Update
I made it work with the versions below, but it would still be interesting to know how to test this locally.
¹ specifically I want the following packages:
opencv-python==3.4.3.18
scipy==1.4.1
scikit-learn==0.22.2.post1