繁体   English   中英

无法在 AWS Lambda 中导入 numpy 1.19.1 没有名为“numpy.core._multiarray_umath”的模块

[英]Unable to import numpy 1.19.1 in AWS Lambda No module named 'numpy.core._multiarray_umath'

我无法在 Lambda 上使用 python3.8 在 AWS Lambda 中导入 numpy 1.19.1

我正在使用以下依赖项:

  • pandas 1.1.0
  • pyarrow 1.0.0
  • numpy 1.19.1
  • 心理战2 2.8.5

因为我在 windows 环境中工作,所以我创建了一个 EC2 Linux 实例,安装了 python3.8 并下载了所有必需的库,然后将它们添加到项目中,但是当我尝试导入 pandas 时,我得到以下信息:

[ERROR] ImportError: Unable to import required dependencies:
numpy: 

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

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.8 from "/var/lang/bin/python3.8",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.18.2" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

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

Traceback (most recent call last):
  File "/var/task/src/py38-lib-test.py", line 28, in py38test
    import pandas
  File "/tmp/lib/pandas/__init__.py", line 16, in <module>
    raise ImportError(END RequestId: 07762380-1fc4)

最后,我注意到 AWS Lambda 提供了一个包含 numpy 和 sci-kit 的层,我尝试删除我的 numpy 版本但保留 rest 并将该层添加到 function,但出现相同的错误。

提前感谢您的评论。

您的 ec2 实例是 amazon linux2 机器吗? You could also try building and run a docker image for amazon linux 2 and get the python libs compatible to the environment you need in your Lambda, by volume mounting to your host.

类似于 docker lambda 的东西:

https://github.com/lambci/docker-lambda/tree/master/python3.8

AWS Lambda function 不能以这种方式工作。 如果您打开 Pandas package 它将拥有 Numpy ZEFE90A8E604A7C840E88D03A6 但他们不会与他们一起工作。 简单的解决方案是首先根据您的 python 版本和从站点的工作环境分别下载所需的包,解压缩并将它们添加到您的项目目录中。 为您的项目创建 a.zip 并将其部署在 AWS Lambda function 上。 它会这样工作。 您可以参考 站点以遵循完整的程序。

我使用Klayers提供的层来解决问题。

假设您在us-east-1区域运行 python 3.8,根据此 Klayers 文档,您可以使用arn:aws:lambda:ap-east-1:770693421928:layer:Klayers-python38-numpy:19作为您的 layer:Klayers-python-38这样您就可以在 lambda function 中运行import numpy numpy。

我有同样的问题,尝试用我的基本代码打包所有库,尝试通过分离 numpy 和 pandas 库来自定义 lambda 层。 没有任何效果。

使用默认的 AWS 层。 在默认层中,AWS 提供了 AWSSDKPandas、CodeGuru、Lambda Insights 等层。AWSSDKPandas 层打包了 pandas 库和其他依赖项,如 numpy 等。

因此,我从我的基础 package 中删除了 numpy 依赖项,并将 AWSSDKPandas 添加为 Lambda 层。 工作得很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM