I'm having trouble processing jpeg files in Python under AWS Elastic Beanstalk.
I have this in the .ebextensions / python.config file:
packages: yum: libjpeg-turbo-devel: [] libpng-devel: [] freetype-devel: [] ...
So, I believe that I have libjpeg installed and it works (I tried libjpeg-devel, but yum could not find this package).
Also, I have this on my .txt requirements:
Pillow==2.5.1 ...
So, I believe that I have Pillow installed and working on my environment.
Then, since I have Pillow and libjpeg, I try to do some work using PIL.Image in a Python script and save to a file. Like this:
from PIL import Image def resize_image(image,new_size,crop=False,correctOrientationSize=False): assert type(new_size) == dict assert new_size.has_key('width') and new_size.has_key('height') THUM_SIZE = [new_size['width'],new_size['height']] file_like = cStringIO.StringIO(base64.decodestring(image)) thumbnail = Image.open(file_like) (width,height) = thumbnail.size if correctOrientationSize and height > width: THUM_SIZE.reverse() thumbnail.thumbnail(THUM_SIZE) if crop:
However, when I try to run it on an Elastic Beanstalk instance, the exception is "decoder jpeg not available" when the .save () method is called.
If I SSH into my instance, it works fine, and I was already trying to rebuild the environment.
What am I doing wrong?
UPDATE:
As suggested, I included SSHed in the instance again and reinstalled Pillow via pip (/ opt / python / run / venv / bin / pip), but not earlier than I'm sure libjpeg-devel was in the environment before Pillow.
I ran selftest.py and it confirmed that I have jpeg support. So, in the last attempt, I went to the "Restart App Server" on the Elastic Beanstalk interface. It worked.
Thanks to everyone.
python amazon-web-services elastic-beanstalk python-imaging-library pillow
Pedro alves
source share