gpt4 book ai didi

python - AWS lambda 中的 Pandas 给出了 numpy 错误

转载 作者:IT老高 更新时间:2023-10-28 21:45:50 26 4
gpt4 key购买 nike

我一直在尝试在导入 pandas 的 AWS Lambda 中运行我的代码。这就是我所做的。我有一个 python 文件,其中包含如下简单代码(此文件具有 lambda 处理程序)

import json
print('Loading function')
import pandas as pd
def lambda_handler(event, context):
return "Welcome to Pandas usage in AWS Lambda"
  1. 我已将此 python 文件与 numpy、pandas 和 pytz 库一起压缩为部署包(所有这些都在 Amazon EC2 linux 机器中完成)
  2. 然后将包上传到 S3
  3. 创建了一个 lambda 函数 (runtime=python3.6) 并从 S3 上传了部署包

但是当我在 AWS Lambda 中测试 lambda 函数时,出现以下错误:

Unable to import module 'lambda_function': Missing required dependencies ['numpy']

我已经在压缩包中有 numpy,但我仍然收到此错误。我尝试按照 Pandas & AWS Lambda 给出的提示进行操作。但没有运气。

有没有人遇到过同样的问题。希望有任何解决此问题的提示或建议。

谢谢

最佳答案

要在您的 lambda zip 中包含 numpy,请按照 AWS 文档中此页面上的说明进行操作...

How do I add Python packages with compiled binaries to my deployment package and make the package compatible with AWS Lambda?

以 numpy 为例解释说明:

  1. 在 pypi.org 打开模块页面。 https://pypi.org/project/numpy/
  2. 选择下载文件。

  3. 下载:

对于 Python 2.7,模块名称-版本-cp27-cp27mu-manylinux1_x86_64.whl

例如numpy-1.15.2-cp27-cp27m-manylinux1_x86_64.whl

对于 Python 3.6,模块名称-版本-cp36-cp36m-manylinux1_x86_64.whl

例如numpy-1.15.2-cp36-cp36m-manylinux1_x86_64.whl

  1. 解压/path/to/project-dir 文件夹中的 wheel 文件。您可以在命令行上使用 unzip 命令来执行此操作。显然还有其他方法。

解压 numpy-1.15.2-cp36-cp36m-manylinux1_x86_64.whl

wheel 文件解压后,您的部署包将与 Lambda 兼容。

希望一切都有意义;)

最终结果可能看起来像这样。注意:您不应该在部署包中包含 whl 文件。

What it might look like

关于python - AWS lambda 中的 Pandas 给出了 numpy 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43877692/

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