I'm trying to use Numpy and Scipy in my AWS Lambda function through a layer, but I'm running into issues. Despite following a LinkedIn tutorial (which is a bit outdated), I keep getting an error that says: "Unable to import module 'lambda_function': Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python interpreter from there." I'm using Python 3.13 and would appreciate any help on how to resolve this!
1 Answer
To fix this, make sure you're installing Numpy and Scipy for the correct OS and architecture. You can do this easily by using specific flags when you install. Try these commands:
```
mkdir python
pip install numpy scipy --platform manylinux2014_x86_64 --only-binary=:all: -t python
zip -r numpy313.zip python
```
After that, upload the zip to your S3 bucket and create your layer from it. This worked for me! Now I can import both libraries without issues.
It worked! Thank you so much! How did you figure that out? I often feel lost when it comes to these technical details.