skip to Main Content

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.

4

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. In your requirements.txt file you probably didn’t specify a specific version for opencv-python-headless – Thus each time you deploy a new image it installs the newest one. And… guess what… the newest release was 2 weeks ago – and it appears not to be compatible with your environment. So:

    1. Always specify the specific version you are using.
    2. Specify version 4.6.0.66, as @job-heersink suggested.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search