Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

cannot import name '_imaging' from 'PIL' in Lambda

Open PremKumarSharma1867 opened this issue 3 years ago • 2 comments

Hi,

Hope you are doing well!

Can you please help in fixing python “PIL” error when I am calling it from AWS Lambda? This will help me a lot.

The code (given below) works fine in pycharm (python version 3.10). But I am getting below error when I call PIL in Lambda:

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': cannot import name '_imaging' from 'PIL' (/opt/python/PIL/init.py)

Code that I am running:

import pywhatkit
import pyautogui
import datetime
import time

def send_whatsapp_msg(v_mobile, v_country_code, v_msg):

pywhatkit.sendwhatmsg_instantly(v_country_code+v_mobile, v_msg, 10)

time.sleep(2)   # Give 2 seconds time before pressing ENTER Key
pyautogui.press("enter")    # Press ENTER Key
pyautogui.press("enter")    # Press ENTER Key again for safer side

return True

Thanks in advance! Best Regards, Prem Sharma (he/him)

PremKumarSharma1867 avatar Sep 16 '22 05:09 PremKumarSharma1867

Is anything at https://stackoverflow.com/questions/57197283/aws-lambda-cannot-import-name-imaging-from-pil helpful?

It suggests

radarhere avatar Sep 16 '22 08:09 radarhere

In https://web.archive.org/web/20210126181708/https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example-deployment-pkg.html#with-s3-example-deployment-pkg-python, the official answer is

We recommend using the AWS SAM CLI sam build command with the --use-container option to create deployment packages that contain libraries written in C or C++, such as the Pillow (PIL) library.

radarhere avatar Sep 18 '22 06:09 radarhere

Closing this issue as no feedback has been received.

github-actions[bot] avatar Sep 27 '22 00:09 github-actions[bot]