Klayers icon indicating copy to clipboard operation
Klayers copied to clipboard

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

Open labenz opened this issue 3 years ago • 15 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!

labenz avatar Jun 29 '22 21:06 labenz

does anything from https://github.com/keithrozario/Klayers/issues/154 help?

keithrozario avatar Jun 30 '22 04:06 keithrozario

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!

labenz avatar Jun 30 '22 13:06 labenz

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

keithrozario avatar Jul 01 '22 01:07 keithrozario

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 avatar Jul 05 '22 15:07 labenz

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!

labenz avatar Jul 05 '22 15:07 labenz

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.

keithrozario avatar Jul 06 '22 00:07 keithrozario

understood – thank you!

labenz avatar Jul 06 '22 20:07 labenz

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?

sladg avatar Dec 23 '22 11:12 sladg

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 avatar Dec 24 '22 04:12 talicopanda

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

mmonkey avatar Feb 02 '23 05:02 mmonkey

I see That 's a good idea

Stone-Giant avatar Feb 17 '23 20:02 Stone-Giant

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!

sabitm avatar Mar 07 '23 04:03 sabitm

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

Stone-Giant avatar Mar 27 '23 06:03 Stone-Giant

  • 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.

dnyaneshbqt avatar Apr 21 '23 08:04 dnyaneshbqt

@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

YannaiKO avatar May 07 '23 20:05 YannaiKO