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' ? #221

Open
labenz opened this issue Jun 29, 2022 · 15 comments
Open

[BUG] cannot import name '_imaging' from 'PIL' ? #221

labenz opened this issue Jun 29, 2022 · 15 comments
Assignees

Comments

@labenz
Copy link

labenz commented Jun 29, 2022

Hello, just discovered this project and excited about it – so I apologize if this is a rookie mistake somehow, but I'm trying to use the Pillow layer and getting this error. The layer attached to the Lambda function without any trouble, and I'm stilling trying to run

from PIL import Image when I'm seeing this error

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

Describe the bug
can't load the Pillow library despite adding layer to Lambda function

Layer Version ARN:
I tried two, got the same result from each

  • arn:aws:lambda:us-east-1:770693421928:layer:Klayers-p38-Pillow:3
  • arn:aws:lambda:us-east-1:770693421928:layer:Klayers-p38-Pillow:2

Framework:
Console

Additional context
Appreciate your work on this!

@keithrozario
Copy link
Owner

does anything from #154 help?

@labenz
Copy link
Author

labenz commented Jun 30, 2022

thanks for the pointer! Changing the runtime to Python 3.8 worked, as suggested here

Neither 3.7 nor 3.9 worked, though, so there does still seem to be an issue out there, but it's no longer blocking me.

Fwiw, here's what the layer looks like installed on my function – I didn't think to try another runtime until reading the other thread.

Screen Shot 2022-06-30 at 9 44 28 AM

Appreciate it!

@keithrozario
Copy link
Owner

the layers with p38 in the name are built for Python 3.8 and will only work with p3.8 :)

@labenz
Copy link
Author

labenz commented Jul 5, 2022

thanks for the clarification. at the risk of asking another newb question... is there a reason many packages available in 3.8 are not available in 3.9? I notice that Pillow, for example, is not available in 3.9. thanks again!

@labenz
Copy link
Author

labenz commented Jul 5, 2022

and one more possibly dumb question: is there a reason that common ML packages are not included in this project? I'm thinking about things like...

  • transformers
  • timm
  • torch
  • torchvision

I guess one possible reason is that, since I need all of these for what I'm building, I would not be able to use all of them, as I'd hit the max layers limit of 5. any other reason?

Appreciate it!

@keithrozario
Copy link
Owner

No such thing as dumb questions -- only dumb answers :)

But generally the AI/ML packages are too large to fit into layers. Layers have a limit of 250MB uncompressed, and sometimes these layers can easily exceed that.

@labenz
Copy link
Author

labenz commented Jul 6, 2022

understood – thank you!

@sladg
Copy link

sladg commented Dec 23, 2022

Experienced same issue, p38 in name is kinda confusing considering the layer description includes all Python3 versions. Any chance this could be clarified on layer description?

@talicopanda
Copy link

I've also been having the same issue and it doesn't seem to be fixed by changing runtime versions or adding a layer based on these ARNs. For context, I uploaded a virtual environment zip file that includes my code with imported modules, and it seems that one of these imported modules rely on Pillow.

@mmonkey
Copy link

mmonkey commented Feb 2, 2023

@talicopanda I was having the same issue until I recreated my lambda function to use runtime of x86_64 instead of arm64

@Stone-Giant
Copy link

I see
That 's a good idea

@sabitm
Copy link

sabitm commented Mar 7, 2023

Hi, I'm using pillow 9.2.0 arn for ap-southeast-1 and wondered if it will support arm64 someday? It will be immensly helpful! I'm currently running the problem like what OP did. I'm using the right version of python (3.9 with p39 pillow) but the error still occur.

Thanks for your great work!

@Stone-Giant
Copy link

Hello I have checked your problems carefully>
So first of all you have to import appropriate packages.
Maybe In my opinion you have to need packages as below.

PIL 
Pillow.libs  
Pillow-9.4.0.dist-info 
Lambda_function.py

@dnyaneshbqt
Copy link

  • arn:aws:lambda:us-east-1:770693421928:layer:Klayers-p38-Pillow:3

I have tried same arn but still having the issue can you help me to fix this.

@YannaiKO
Copy link

YannaiKO commented May 7, 2023

@dnyaneshbqt my solution was:

  1. Removing PIL from the package (using poetry)
  2. Adding the layer from the serverless.yml file, and not the aws lambda site/UI

hope this helps

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

9 participants