AWS lambda 无法导入模块“lambda_function":没有名为 PIL 的模块 [英] AWS lambda Unable to import module 'lambda_function': No module named PIL

查看:40
本文介绍了AWS lambda 无法导入模块“lambda_function":没有名为 PIL 的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SearchFacesbyimage 的 lambda 函数并且我正在使用这个文档 https://aws.amazon.com/blogs/machine-learning/build-your-own-face-recognition-service-using-amazon-rekognition/

I am using a lambda function of SearchFacesbyimage And I am using this doc https://aws.amazon.com/blogs/machine-learning/build-your-own-face-recognition-service-using-amazon-rekognition/

我在哪里使用这个进行比较

where for comparison I am using this

from PIL import Image

我收到此错误无法导入模块lambda_function":没有名为 PIL 的模块

推荐答案

我也遇到了这个完全相同的问题.您可以在此处执行两个步骤:手动与自动打包和部署.

I also ran into this exact same problem. There are two steps that you can take here: manual versus automated packaging and deploying.

手动步骤将涉及创建正确的 virtualenv 并在该虚拟环境中安装依赖项.然后压缩所有内容并上传到 AWS.

The manual step would involve creating the correct virtualenv and install dependencies in that virtual environment. Then zip everything and upload to AWS.

为了自动化,我总是更喜欢使用无服务器框架来打包和部署 Lambda 函数.特别是 python-requirements-plugin 有助于打包.但是我必须指定以下内容来告诉框架在 docker 容器中构建并且不要剥离任何库:

To automate stuff, I always prefer to use the Serverless framework to package and deploy Lambda functions. Specifically the python-requirements-plugin helps with packaging. But I do have to specify the following things to tell the framework to build within a docker container and don't strip any libraries:

custom:
  pythonRequirements:
    dockerizePip: true
    strip: false

这篇关于AWS lambda 无法导入模块“lambda_function":没有名为 PIL 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆