Question:
Is there a way to install numpy
on a Mac so that it will work when uploaded to AWS Lambda? I have tried a variety of different ways, including using different pip
versions, using easy_install
, and following this post, but none of them seem to work. I also tried cloning the git repo and building from there, but I also wasn’t able to get that to work (though I’m not sure if I copied the right files up after doing that)
The error I’m getting is:
Unable to import module ‘lambda_function’: Importing the multiarray
numpy extension module failed. Most likely you are trying to import a
failed build of numpy. If you’re working with a numpy git repo, try
git clean -xdf
(removes all files not under version control).
Otherwise reinstall numpy.
Inspired by this post, I was able to pip install
numpy
in a Linux environment and get it to work on Lambda.
So my question is: Is it possible to install numpy
on a Mac so that it works on AWS Lambda?
Environment: MacBook Pro, MacOS 10.12.2, default python version 2.7.10
I’ve been testing it with a minor variation on the hello-world-python
example on Lambda:
1 2 3 4 5 6 7 |
from __future__ import print_function import numpy def lambda_handler(event, context): #print("Received event: " + json.dumps(event, indent=2)) print("value1 = " + event['key1']) |
(Update) Extending the question: Why do some packages work and others don’t?
Answer:
Building on @MarkB’s comment, it would not be possible to build numpy
on a Mac to use on AWS Lambda. So why do some packages work and others don’t?
Python extension modules, as explained on Mark Nunnikhoven’s blog here, are
written in C or C++ that can either extend python or call C or C++
libraries.
Since these modules are compiled specific to the system you’re on, and AWS Lambda is a Linux environment, you’ll need to install any extension modules on a Linux environment.