cannot import name '_imaging' from 'PIL' in Lambda
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)
Is anything at https://stackoverflow.com/questions/57197283/aws-lambda-cannot-import-name-imaging-from-pil helpful?
It suggests
- unzipping the relevant Pillow wheel and uploading those to your lambda, or
- if you don't strictly need to use Python 3.10, https://github.com/keithrozario/Klayers supports Python 3.9
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.
Closing this issue as no feedback has been received.