By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Cannot import numba python package inside AWS Lambda function

1

I have an AWS Lambda function with Python 3.7 runtime and AWSLambda-Python37-SciPy1x lambda layer added. I have my python dependencies (such as numba) installed on a EFS directory that I add to the path that the Lambda function can access. (I installed numba with pip install --target . numba==0.47.0, for version 0.47.0, for example)

I can inport numpy, but trying to import numba gives the following error:

Runtime.ImportModuleError: Unable to import module 'lambda_function': Numba could not be imported.
If you are seeing this message and are undertaking Numba development work, you may need to re-run:
python setup.py build_ext --inplace
(Also, please check the development set up guide http://numba.pydata.org/numba-doc/latest/developer/contributing.html.)
If you are not working on Numba development:
Please report the error message and traceback, along with a minimal reproducer
at: https://github.com/numba/numba/issues/new
If more help is needed please feel free to speak to the Numba core developers
directly at: https://gitter.im/numba/numba
Thanks in advance for your help in improving Numba!
The original error was: 'cannot import name '_typeconv' from 'numba.typeconv' (/mnt/access/numba/typeconv/__init__.py)'
--------------------------------------------------------------------------------
If possible please include the following in your error report:
sys.executable: /var/lang/bin/python3.7
Traceback (most recent call last):

I tried with the numba versions 0.45.0, 0.47.0, 0.48.0, 0.49.0, 0.49.1, 0.55.1 and the error is the same in all versions.

I saw this response, but when I delete de numba files from the EFS directory, i get a No module named 'numba' error, which indicates that there is no other numba version installed.

Below is the full code of the AWS Lambda function:

import sys

sys.path.append("/mnt/access")

import os, json, sys

import numba 


def lambda_handler(event, context):

    return {
        'statusCode': 200,
        'body': json.dumps('All OK')
    }

Is there a specific way I should be installing numba?

*ps: I describe this exact problem in this issue on the numba repository, but unfortunately the numba mainteiners do not have familiarity with aws lambda, so I coundn't get help.

  • Any solution to-date?

asked 3 years ago1.3K views
2 Answers
1

Has this issue been resolved ?

answered 2 years ago
0

You may be interested in using anaconda-project to build a Docker image for AWS Lambda

You could write an anaconda-project.yml as shown below. When building the image using source-to-image (s2i) or anaconda-project dockerize all dependencies (pip and conda) are included in the image.

There is a special entrypoint just for AWS Lambda usage that you set when you create the lambda function.

https://github.com/Anaconda-Platform/s2i-anaconda-project#entrypoints

name: lambda-with-numba

packages:
  - python=3.7
  - numpy
  - numba
  - pip
  - pip:
    - awslambdaric

commands:
  default:
    unix: python -m awslambdaric <file>.<handler_func>
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions