简体   繁体   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'

I am unable to import numpy 1.19.1 in AWS Lambda with python3.8 on AWS Lambda我无法在 Lambda 上使用 python3.8 在 AWS Lambda 中导入 numpy 1.19.1

I am using the following dependencies:我正在使用以下依赖项:

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

Because I work on a windows environment, I created an EC2 Linux instance installed python3.8 and downloaded all required libraries, then I added them into the project, but the moment I try to import pandas I get the following:因为我在 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)

Lastly, I noticed AWS Lambda provides a layer with numpy and sci-kit, I tried removing my numpy version but kept the rest and added the layer to the function, but the same error occurs.最后,我注意到 AWS Lambda 提供了一个包含 numpy 和 sci-kit 的层,我尝试删除我的 numpy 版本但保留 rest 并将该层添加到 function,但出现相同的错误。

Thanks in advance your comments.提前感谢您的评论。

Is your ec2 instance an amazon linux2 machine?您的 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. 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.

Something similat to docker lambda:类似于 docker lambda 的东西:

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

AWS Lambda function don't work this way. AWS Lambda function 不能以这种方式工作。 If you open the Pandas package it'll be having the Numpy package with them but they would not work.如果您打开 Pandas package 它将拥有 Numpy ZEFE90A8E604A7C840E88D03A6 但他们不会与他们一起工作。 The easy solution is to first download the required packages separately depending upon your python version and work enviroment from this site, unzip them and add them to your project directory.简单的解决方案是首先根据您的 python 版本和从站点的工作环境分别下载所需的包,解压缩并将它们添加到您的项目目录中。 Create a.zip of your project and deploy it on AWS Lambda function.为您的项目创建 a.zip 并将其部署在 AWS Lambda function 上。 It'll work this way.它会这样工作。 You can refer to this site in order to follow the complete procedure.您可以参考 站点以遵循完整的程序。

I use the layer provided by Klayers to solve the problem.我使用Klayers提供的层来解决问题。

Suppose you're running python 3.8 in us-east-1 region, according to this Klayers document , you can use arn:aws:lambda:ap-east-1:770693421928:layer:Klayers-python38-numpy:19 as your layer so that you can run import numpy in the lambda function.假设您在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。

I had the same issue, tried packaging all libs with my base code, tried custom lambda layer by separating numpy and pandas libs.我有同样的问题,尝试用我的基本代码打包所有库,尝试通过分离 numpy 和 pandas 库来自定义 lambda 层。 Nothing worked.没有任何效果。

Used default AWS Layers.使用默认的 AWS 层。 In the default layers, AWS provides layers like AWSSDKPandas, CodeGuru, Lambda Insights, etc. AWSSDKPandas layer is packaged with pandas libs and other dependencies like numpy, etc.在默认层中,AWS 提供了 AWSSDKPandas、CodeGuru、Lambda Insights 等层。AWSSDKPandas 层打包了 pandas 库和其他依赖项,如 numpy 等。

So I removed numpy dependency from my base package and added AWSSDKPandas as Lambda layer.因此,我从我的基础 package 中删除了 numpy 依赖项,并将 AWSSDKPandas 添加为 Lambda 层。 Worked well.工作得很好。

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

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