Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
merc1er opened this issue Apr 23, 2021 · 15 comments
Closed

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

merc1er opened this issue Apr 23, 2021 · 15 comments
Assignees

Comments

@merc1er
Copy link

merc1er commented Apr 23, 2021

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
Copy link

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

@DylanAlbertazzi
Copy link

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
Copy link
Owner

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

@DylanAlbertazzi
Copy link

DylanAlbertazzi commented May 3, 2021

@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
Copy link
Author

merc1er commented May 3, 2021

It looks like Pillow no longer supports _imaging

I am not importing _imaging @DylanAlbertazzi

@subratamal
Copy link

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
Copy link

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
Copy link

ghost commented Apr 20, 2023

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
Copy link

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
Copy link

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
Copy link

Adorp94 commented Jan 21, 2024

@kxngdavid @jasonrdunne Did you got to resolve it?

@Adorp94
Copy link

Adorp94 commented Jan 21, 2024

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
Copy link

kxngdavid commented Jan 22, 2024 via email

@SAINTZST
Copy link

SAINTZST commented May 9, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants