gpt4 book ai didi

python - 尝试在 AWS Lambda 中使用 Pillow 时无法导入名称 '_imaging'

转载 作者:行者123 更新时间:2023-11-28 17:04:45 27 4
gpt4 key购买 nike

我正在尝试创建使用 PIL 的 AWS Lambda 函数。因此我在我的项目目录中安装了 PIL

pip install Pillow -t .

第一次在本地机器上运行,导致

ImportError: cannot import name '_imaging'

虽然我做错了什么并从项目目录中删除了 PIPPillow* 目录并重新安装了 PIL。然后它起作用了。

不幸的是,当我将所有内容打包成 ZIP 并发布到 AWS 时,该功能再次开始失败

Traceback (most recent call last):
File "/var/task/myfile.py", line 9, in lambda_handler
from PIL import Image
File "/var/task/PIL/Image.py", line 64, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging'

此错误的确切原因是什么以及如何解决?

下面是我的项目目录中的文件列表:

$ ls
bin chardet-3.0.4.dist-info Pillow-5.2.0.dist-info ThumbnailEnergent_Lambda.zip
certifi idna requests myfile.py
certifi-2018.4.16.dist-info idna-2.7.dist-info requests-2.19.1.dist-info urllib3
chardet PIL tests urllib3-1.23.dist-info

最佳答案

我今天确实遇到了这个问题,发现我的 Lambda 运行时语言是 python3.6,因为我使用的是从早期项目复制的 Cloudformation 模板。问题是我已经使用 Python 3.7 下载了 Pillow 作为我的 zip 文件,并且 Pillow 将其 _imaging C 模块文件命名为 Python 运行时。

为了解决这个问题,我只需要将我的运行时语言从 Python 3.6 更改为 Python 3.7。因此,只需确保上传脚本和 Lambda 函数的 Python 版本完全相同即可。

关于python - 尝试在 AWS Lambda 中使用 Pillow 时无法导入名称 '_imaging',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51754561/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com