keithrozario / Klayers

Python Packages as AWS Lambda Layers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No module named 'numpy.core._multiarray_umath' using your latest numpy 1.22.1 lambda layer in us-east-1

sreerammeka opened this issue · comments

@keithrozario I'm using your numpy 1.22.1 layer ARN in us-east-1: arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-numpy:25 and receiving the following error on Python 3.8 .

I have also tried building my own numpy layer both using pip and wheels using latest pip (pip 21.3.1) and Python 3.8 on Amazon Linux 2, but still receiving numpy "Importing the numpy C-extensions failed" and "No module named 'numpy.core._multiarray_umath'".

Note: Sample code like the code below works in a lambda function even with the numpy layers I created but when using this same lambda layer in a different lambda function which performs some kind of functionality throws this numpy C-extensions error and "No module named 'numpy.core._multiarray_umath'" error.

import json
import numpy

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

Error
{
"errorMessage": "Unable to import module 'handler': Unable to import required dependencies:\nnumpy: \n\nIMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the numpy C-extensions failed. This error can happen for\nmany reasons, often due to issues with your setup or how NumPy was\ninstalled.\n\nWe have compiled some common reasons and troubleshooting tips at:\n\n https://numpy.org/devdocs/user/troubleshooting-importerror.html\n\nPlease note and check the following:\n\n * The Python version is: Python3.8 from "/var/lang/bin/python3.8"\n * The NumPy version is: "1.19.5"\n\nand make sure that they are the versions you expect.\nPlease carefully study the documentation linked above for further help.\n\nOriginal error was: No module named 'numpy.core._multiarray_umath'\n",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []

Strange that they're asking for version 1.19.5 :(. Not sure what's the issue is here. Hopefully a numpy expert can chime in.

I'm having this issue too

@sreerammeka @keithrozario any update on this? I'm still facing the same issue.

@HimanshuSharma-Angel I'm using the serverless framework with python 3.6 inside a docker container so the problem here is serverless framework is packaging using python 3.6 even though the serverless.yml configuration has a Python runtime version parameter set to python 3.8. It's strange that this issue is not occurring for some of the python 3.8 projects deployed with this python 3.6 docker container.

Creating a new Docker container with python 3.8 and latest pip3 to deploy applications resolved this issue.

Note: I haven't used this Klayers for numpy and I created a numpy layer on Python 3.8 to resolve this issue.

I've been having a similar issue when trying to get spacy to run on Lamda using the layers that Keith prepared (thank you very much Keith).

What I noticed is that I'm able to reproduce this bug when using the wrong version of Python. I think the spacy layer arn:aws:lambda:eu-central-1:770693421928:layer:Klayers-python38-spacy:42 includes numphy but I made the mistake of running it as Python 3.7 instead of 3.8 because the ARN was listed under that section. In part because on AWS it shows that it is compatible as well with 3.7 and 3.6. This seemed like the smart choice given that the spacy model arn:aws:lambda:eu-central-1:770693421928:layer:Klayers-python38-spacy_model_en_small:1 only targets 3.7.

The summary of what I'm saying is: make sure that the selected Python version of the Lambda matches the version targeted. Maybe some trial and error helps..

I'll see if I have time over the weekend to manually tweak this -- hope it's not expired already :)

On ready