AWS Lambda:无法从"PIL"导入名称"_imaging" [英] AWS Lambda: cannot import name '_imaging' from 'PIL'

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

问题描述

我目前正在尝试运行此AWS Lambda入门教程:

解决方案

尽管尝试了所有这些步骤,但我仍然遇到错误.终于我找到了我的问题:)

对我来说,AWS Lamda运行时中的Python版本是 python 3.7.7 .我使用 python 3.6安装了Pillow. PIL与不同版本的python的兼容性似乎存在一些问题.

因此,要解决此问题,请将AWS lambda运行时更改为python3.6.(这是我尝试并做过的事情)

或者,也可以尝试为python 3.7.7安装枕头并将其复制到lambda.

由于cython存在问题,首选的方法是使用Amazon Linux在EC2中安装软件包或使用AWS AMI docker映像.

I currently try to get this AWS Lambda Getting started tutorial running: https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example-deployment-pkg.html#with-s3-example-deployment-pkg-python

However, I always receive an error:

{
  "errorMessage": "Unable to import module 'CreateThumbnail': cannot import name '_imaging' from 'PIL' (/var/task/PIL/__init__.py)",
  "errorType": "Runtime.ImportModuleError"
}

Log output

START RequestId: fefba1d1-443c-4617-a5ad-c3aac19e5591 Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'CreateThumbnail': cannot import name '_imaging' from 'PIL' (/var/task/PIL/__init__.py)
END RequestId: fefba1d1-443c-4617-a5ad-c3aac19e5591
REPORT RequestId: fefba1d1-443c-4617-a5ad-c3aac19e5591  Duration: 1.52 ms   Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory Used: 71 MB  

I went that far to build my .zip from a lambci/docker-lambda image. But it didn't resolve my problem.

Here what's inside my .zip. Do you have any ideas, why I still get this error?

解决方案

I was still facing the error despite trying all these steps. Finally I was able to find my issue :)

For me the Python version in AWS Lamda runtime was python 3.7.7. I installed Pillow using python 3.6. There seems to be some issue with compatibility of PIL with differnt versions of python.

So to resolve the issue either change AWS lambda runtime to python3.6.( This is what I tried and did work)

Alternatively one could also try installing pillow for python 3.7.7 and copying this to lambda.

As there are issues with cython the preferrable way would be to install packages in EC2 with amazon linux or using a AWS AMI docker image.

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

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