0

I'm working on a lambda function that partly depends on numpy. I created a deployment package zip with a test script that imports numpy and then tries to subtract two numbers using np.subtract since it was having trouble finding the numpy functions.

import numpy as np 
a = np.subtract(4,2)
print(a)

I'm working with a python3.5 virtualenv on a linux EC2 instance. To create the deployment zip, I installed numpy, placed my script into site-packages and zipped the contents of the folder as described here. I can create the lambda function from the zip file with no problem, but when I trigger it, it gives the error:

module initialization error: module 'numpy' has no attribute 'subtract'

It appears to import numpy, but it can't find any of the functions. I assume I packaged the libraries/script wrong, but I thought I was following the directions correctly. Any help would be appreciated!

Ian Marci
  • 141
  • 1
  • 8

2 Answers2

0

I think you need to reference the module when you import it. A bit of code always helps.

import numpy

a=2
b=1
c=numpy.subtract(a,b)
print c
MLMiller
  • 29
  • 5
  • Maybe it would be better if I didn't reference it as np, but did it directly like you did? Edited the main question to include the test code. – Ian Marci Aug 31 '17 at 15:16
  • The package might need to be unzipped for access to numpy? Does it work local, just not on EC2? – MLMiller Aug 31 '17 at 15:40
0

For future reference, a similar question was asked here, and I was able to adapt the solution for my needs. It was how I packaged the libraries.

Ian Marci
  • 141
  • 1
  • 8