有没有办法在 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 等无缝导入到您的代码中。
关于python - 在 Mac 上安装 numpy 以在 AWS Lambda 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42534850/