question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error importing numpy in AWS Lambda

See original GitHub issue

I was trying to deploy a python package in AWS Lambda following the instruction from https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html. I include numpy as my dependency in my deployment package. However, when I upload my deployment zip file onto lambda. There is always an import error like this:

[ERROR] Runtime.ImportModuleError: Unable to import module 'plotting_function': 

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

Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
  your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
  1. Check that you are using the Python you expect (you're using /var/lang/bin/python3.7),
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy versions 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

     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'

My OS is Mac and my python version is 3.7. I installed numpy by using pip install lumpy --target . from https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

Can someone help me? Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jamesshapirocommented, Mar 5, 2019

I would also recommend https://serverless.com/blog/serverless-python-packaging/

Note that I had to add:

package: exclude: - venv/**

… to the end of my serverless.yml file in order to get the .zip file small enough to successfully load in Lambda.

1reaction
jamesshapirocommented, Nov 26, 2019

Current best practices are to import numpy as a lambda layer. See here: https://stackoverflow.com/questions/42534850/installing-numpy-on-mac-to-work-on-aws-lambda/58136903#58136903

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pandas in AWS lambda gives numpy error - Stack Overflow
One of the dependencies of Pandas is Numpy (which is compiled due to speed, see this answer on stackoverflow). AWS Lambda uses Linux...
Read more >
Unable to import numpy in AWS Lambda function · Issue #13465
Since I am installing to run on AWS Lambda, pip install numpy --target . your operating ... Original error was: No module named...
Read more >
Resolve "Unable to import module" errors from Python ...
I receive an "Unable to import module" error when I try to run my AWS Lambda code in Python. How do I resolve...
Read more >
AWS Lambda with Pandas and NumPy - Ruslan Korniichuk
AWS Lambda does not include Pandas/NumPy Python libraries by default. ... Unable to import module 'lambda_function': No module named 'pandas'.
Read more >
how to import numpy and pandas inside aws lambda function
i am trying to import numpy inside my aws lambda function but error was thrown as Unable to import module 'aws_lambda_demo/lambda_function': No ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found