I am developing a lambda function with python3.6. It uses pytesseract library to convert image to text. I created layer with below folder structure.
python/lib/python3.6/site-packages/PIL
python/lib/python3.6/site-packages/Pillow-6.2.1.dist-info
python/lib/python3.6/site-packages/pytesseract
python/lib/python3.6/site-packages/pytesseract-0.3.1.dist-info
Compressed 'python' folder (as shown above) and uploaded to layers in AWS.
My lambda function code is as below. My code is in python3.6
from PIL import Image
import pytesseract
import json
def lambda_handler(event, context):
print(pytesseract.image_to_string(Image.open('image002.jpg')))
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
But when I run code I get below error
Unable to import module 'lambda_function': cannot import name '_imaging'
This error is because it is unable to find pillow library (PIL). But it is already included in site-packages folder. I believe there would be some mistake folder structure of layers.
I already tried with folder strutures as guided in below links but no success:
https://stackoverflow.com/a/55711008/1030951
https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html