python - 在 Mac 上安装 numpy 以在 AWS Lambda 上工作

标签 python amazon-web-services aws-lambda

有没有办法在 Mac 上安装 numpy,以便它在上传到 AWS Lambda 时可以正常工作?我尝试了多种不同的方式,包括使用不同的 pip 版本、使用 easy_install 以及遵循 this post ,但它们似乎都不起作用。我也尝试克隆 git repo 并从那里构建,但我也无法让它工作(尽管我不确定在这样做之后我是否复制了正确的文件)

我得到的错误是:

Unable to import module 'lambda_function': Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try git clean -xdf (removes all files not under version control). Otherwise reinstall numpy.

灵感来自 this post ,我能够在 Linux 环境中 pip install numpy 并使其在 Lambda 上运行。

所以我的问题是:是否可以在 Mac 上安装 numpy 以便它在 AWS Lambda 上运行?

环境:MacBook Pro,MacOS 10.12.2,默认python版本2.7.10

我一直在使用 Lambda 上的 hello-world-python 示例的一个小变体来测试它:

from __future__ import print_function
import numpy

def lambda_handler(event, context):
    #print("Received event: " + json.dumps(event, indent=2))
    print("value1 = " + event['key1'])

(更新)扩展问题:为什么有些软件包有效而其他软件包无效?

最佳答案

更新:现在首选的方法是只使用 AWS 为 NumPy/SciPy 提供的 Lambda 层,这非常容易做到。

在控制台中,选择您的函数,然后在“设计”部分下单击“图层”。然后单击“添加层”,并在 AWS Provided 下选择“AWSLambda-Python37-SciPy1x”(或您正在使用的 Python 版本的任何等效项)。

然后您可以毫无问题地将 numpy、scipy 等无缝导入到您的代码中。

10/26/2020 - 添加了示例屏幕截图: enter image description here

enter image description here

关于python - 在 Mac 上安装 numpy 以在 AWS Lambda 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42534850/

相关文章:

python - Pandas 日期时间系列的累计经过分钟数

python - 在 Windows 上制作 python 独立 Linux 可执行文件

python - 如何将数据从 python 传递到 php?

amazon-web-services - SQS 的 ApproximateReceiveCount 有多准确

postgresql - terraform 和 aurora postgresql 的存储类型错误

amazon-web-services - 找不到 Golang 的 API 网关映射模板

amazon-web-services - AWS Lambda 无法删除 Amazon S3 对象

python - 如何使用 Plotly-Dash 调整 slider 和选择器的范围

php - 如何通过 EC2 Windows Server 和 XAMPP 设置来获取 URL 来托管 PHP 服务器?

mysql - AWS Lambda - MySQL 缓存