"Unable to import module 'lambda_function': cannot import name '_imaging' from 'PIL' (/var/task/PIL/__init__.py)"

0

Hi, I'm facing the above error when I try to use PIL package (Image module) for image conversion functionality in lambda function. I tried different methods like Adding zip folder in Layer and using that layer in lambda function/package PIL library folder along with lambda function then zip it (from new venv). it did not work.my python version 3.10 and lambda function is 3.10. below is sample code. the code works in local but not in AWS console Lambda function. import os import PIL from PIL import Image def lambda_function(event, context): s3_object_name= 'C:/./tiffimage.TIFF' conversion_folder_path = 'C:/.' s3_obj_file_type = str(s3_object_name).split(".")[-1] print(s3_obj_file_type) if s3_obj_file_type == 'TIFF': any_image1 = Image.open(s3_object_name) new_image_1 = any_image1.convert('RGB') new_image_1.save(conversion_folder_path+'/'+'new_converted_tiff8.jpg', 'JPEG')

any suggestion helps!

Raj-1
질문됨 5달 전775회 조회
1개 답변
0

Hi Raj-1,

Did you try to package PIL using these instructions? Note the directory structure in Step 5 for the relative position of dependencies and the function. You can also create the zip file from a venv, shown here.

Hope this helps. Mike

AWS
Mike_E
답변함 5달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠