【问题标题】:numpy error when importing pandas with AWS Lambda使用 AWS Lambda 导入熊猫时出现 numpy 错误
【发布时间】:2021-10-12 07:21:50
【问题描述】:

我目前在将库 pandas 导入我的 AWS Lambda 函数时遇到问题。我尝试了两种方案。

  • 使用我的lambda_function 将 pandas 直接安装到一个文件夹中并上传压缩文件。

  • 使用上传的 zip 文件创建一个层,其结构如下:

- python
    - lib
        - python3.8
            - site-packages
                - all the pandas packages here

我的lambda_function 只是:

import json
import pandas as pd

def lambda_handler(event, context):
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

这是我的错误:

START RequestId: 9e27641e-587b-4be2-b9be-c9be85007f9e Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'main': Unable to import required dependencies:
numpy: 

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.8 from "/var/lang/bin/python3.8"
  * The NumPy version is: "1.21.1"

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'

还有其他方法吗?我不想使用 Docker 来完成这项任务。谢谢!

【问题讨论】:

    标签: python pandas amazon-web-services numpy aws-lambda


    【解决方案1】:

    感谢这篇文章,我已经解决了这个问题:

    https://korniichuk.medium.com/lambda-with-pandas-fd81aa2ff25e

    就我而言,我通常无法通过 pip 安装库,我在 Windows 机器上。 您必须安装 linux 版本的 pandas 和 numpy。由于我使用的是 python 3.8,因此我安装了这些版本:

    • numpy-1.21.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
    • pandas-1.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

    下载软件包后,我替换了最初通过pip install pandas 安装的 pandas 和 numpy 文件夹。我使用了我的问题中显示的第一个场景。

    【讨论】:

      【解决方案2】:

      只是补充一下,这里是一些非常有用的库作为层的集合

      AWSome Lambda Layers

      向贡献者致敬!

      【讨论】:

        猜你喜欢
        • 2018-12-27
        • 2020-04-05
        • 2020-09-25
        • 1970-01-01
        • 2023-04-01
        • 1970-01-01
        • 2014-11-07
        • 2016-07-03
        相关资源
        最近更新 更多