导入 numpy C 扩展失败(放大)

Importing the numpy C-extensions failed (Amplify)

交叉发布于 GitHub

我正在为我的 python 3.9 lambda 使用 AWS Amplify 和 pipenv。我正在尝试使用 pandas 创建一个数据框,进行一些处理并将其写回 CSV 以进行 sagemaker 推理。

重现代码示例:

import pandas as pd

(此后代码立即失败)

错误信息:

完整的错误信息如下:

[ERROR] Runtime.ImportModuleError: Unable to import module 'index': 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/var/lang/bin/python3.9"
  * The NumPy version is: "1.21.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

我首先使用 pipenv install pandas 下载,它会自动安装 numpy

为了解决我试过:

重要提示我在 Windows 10

我 运行 遇到过类似的问题。经过大量研究,亚马逊提供的 Lambda 层 AWSLambda-Python38-SciPy1x 似乎是您最好的选择。 More Info is here.

您可以像这样通过控制台手动添加图层: Picture for you


或者您可以通过 Amplify CLI 添加图层。我 运行 对现有 lambda 函数执行以下命令:

amplify function update
  • 然后 select 您想要的 Lambda function (serverless function) 将图层添加到。

  • 转到Lambda layers configuration

  • Provide existing Lambda Layer ARN 下提供 ARN。

  • 我用了arn:aws:lambda:us-west-2:420165488524:layer:AWSLambda-Python38-SciPy1x:29

    放大推送

这应该可以解决问题。

切换到较低的 python 版本对我有用。从 python3.8 到 python3.7