In Python, trying to run the opencv package in an AWS lambda layer. Using opencv-python-headless but keep getting this error.
Response
{
"errorMessage": "Unable to import module 'lambda_function': /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by /opt/python/lib/python3.8/site-packages/cv2/../opencv_python_headless.libs/libpng16-186fce2e.so.16.37.0)",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
}
Have tried different versions of opencv to no avail. And different versions of python.
I experienced the same issue as you. This issue occurred only after the latest update of openCV (4.7.0.68). Going back to the previous version 4.6.0.66 fixed the problem for me:
pip install opencv-python-headless==4.6.0.66
This is a known problem with the new update. See this github issue for more info: https://github.com/opencv/opencv-python/issues/772
You can create layer or just (if making layer isn't all mandatory) -
install the necessary libraries in the same directory your lambda code in using pip install opencv-contrib-python -t . (. Means current directory, change if needed).
After downloading all libraries zip them (along with the lambda) and store on a s3 bucket. Then just source lambda from that zip file and you should be good to go.
Best wishes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With