我正在从一个 dockerfile 创建一个 lambda 层,它将 python 包安装到一个目录并压缩结果。
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/
对于这个 Dockerfile,我可以成功部署。
现在我想添加更多库¹,但尽管 docker 构建和上传成功,但在执行 lambda 函数时出现错误(找不到 numpy)。我想要一种比更改 Docker 文件、构建、提取和上传 zip 文件并在 AWS 管理控制台中按“测试”更简单的方法来调试它。
我尝试在本地运行 docker 容器并在那里安装软件包,看看是否可以将所有内容导入 python shell,但我什至无法以这种方式重新创建原始文件:
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
如何找出本地机器上的正确依赖关系?
更新
我使它适用于以下版本,但知道如何在本地测试它仍然很有趣。
¹ 特别是我想要以下软件包:
opencv-python==3.4.3.18
scipy==1.4.1
scikit-learn==0.22.2.post1