keithrozario / Klayers

Python Packages as AWS Lambda Layers
Other
2.17k stars 311 forks source link

[BUG] cannot import name '_imaging' from 'PIL' #154

Closed merc1er closed 3 years ago

merc1er commented 3 years ago

Describe the bug

I am getting the following error when importing anything from PIL using the Pillow ARN.

{
  "errorMessage": "Unable to import module 'lambda_function': cannot import name '_imaging' from 'PIL' (/opt/python/PIL/__init__.py)",
  "errorType": "Runtime.ImportModuleError",
  "stackTrace": []
}

Layer Version ARN:

Pillow 8.2.0 in ap-southeast-1 for Python 3.8.

arn:aws:lambda:ap-southeast-1:770693421928:layer:Klayers-python38-Pillow:10

Framework:

Just console.

Additional context

Here is my code:

from PIL import Image

def lambda_handler(event, context):
    return {
        "statusCode": 200,
        "body": "OK",
    }

Same thing when I do:

import PIL

PIL.Image()

I am using the boto3 layer, and this one is working fine when I import it.

DylanAlbertazzi commented 3 years ago

I'm having the same issue in us-west-2

DylanAlbertazzi commented 3 years ago

It looks like Pillow no longer supports _imaging. See the bottom warning https://pillow.readthedocs.io/en/4.2.x/installation.html "Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from PIL.Image import core as _imaging” instead."

keithrozario commented 3 years ago

Thanks @DylanAlbertazzi , does that mean there's nothing wrong with the layer?

DylanAlbertazzi commented 3 years ago

@keithrozario yep. The layer still works fine 🙂 (on 3.7 in us-west-2)

Side question... Do you know if layers work with lambda function running on greengrass for IoT devices?

I'm guessing you can't because I can't get them to work and don't see any documentation mentioning anything about it.

merc1er commented 3 years ago

It looks like Pillow no longer supports _imaging

I am not importing _imaging @DylanAlbertazzi

subratamal commented 2 years ago

It's not working with me with a very similar setup. There is not much error context as well. Is there a need to set the PATH variable manually?

nuffertaylor commented 2 years ago

if anyone else sees this issue, this was my problem: my lambda runtime was python 3.9, but the max runtime for this klayer is 3.8. switching to 3.8 resolved everything

ghost commented 1 year ago

if anyone else sees this issue, this was my problem: my lambda runtime was python 3.9, but the max runtime for this klayer is 3.8. switching to 3.8 resolved everything

I can agree & use the pillow layer from here: https://github.com/keithrozario/Klayers/tree/master/deployments/python3.8

kxngdavid commented 11 months ago

Can someone please confirm if changing the python runtime to 3.8 still works? cause I did that but I'm still getting the same error.

jasonrdunne commented 11 months ago

Can someone please confirm if changing the python runtime to 3.8 still works? cause I did that but I'm still getting the same error.

same, not sure what to do

Adorp94 commented 9 months ago

@kxngdavid @jasonrdunne Did you got to resolve it?

Adorp94 commented 9 months ago

This medium post helped me resolve it. I had to change the python runtime to 3.8 (both on lambda and the layer). And then add the layer from the ARN, there's a list metioned on the medium post.

kxngdavid commented 9 months ago

Thanks Jason!

Really appreciate!

On Sun, 21 Jan 2024 at 11:38 PM, Adorp94 @.***> wrote:

This medium post https://derekurizar.medium.com/aws-lambda-python-pil-cannot-import-name-imaging-11b2377d31c4 helped me resolve it. I had to change the python runtime to 3.8 (both on lambda and the layer). And then add the layer from the ARN, there's a list metioned on the medium post.

— Reply to this email directly, view it on GitHub https://github.com/keithrozario/Klayers/issues/154#issuecomment-1902805332, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKOLVYFVS3OHAHUQLSQJQ5DYPWRG7AVCNFSM43O66ZNKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJQGI4DANJTGMZA . You are receiving this because you were mentioned.Message ID: @.***>

saintzst commented 6 months ago

if anyone else sees this issue, this was my problem: my lambda runtime was python 3.9, but the max runtime for this klayer is 3.8. switching to 3.8 resolved everything

AWS will block python3.8 from function create/update soon. So, I'm using python3.9. The layer from the repo working well (This ARN arn:aws:lambda:ap-southeast-2:770693421928:layer:Klayers-p39-pillow:1) But when I build the layer myself it throws the same message. Anyone has any idea?

(I did pip install pillow in the linux env via docker, All other packages work fine except for pillow)

numairmansur commented 5 months ago

arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38Pillow:5 does not work for me for Python3.8