keithrozario / Klayers

Python Packages as AWS Lambda Layers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

labenz opened this issue · comments

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!

does anything from #154 help?

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!

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

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!

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!

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.

understood – thank you!

commented

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?

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.

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

I see
That 's a good idea

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!