簡體   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