"jpeg decoder unavailable" with pad on AWS Elastic Beanstalk

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: # Recorta imagem thumbnail = crop_image(thumbnail) output = cStringIO.StringIO() thumbnail.save(output,format='jpeg') return output.getvalue().encode('base64') 

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.

+8
python amazon-web-services elastic-beanstalk python-imaging-library pillow
source share
2 answers

Following the general tips here , I solved this by adding the following to my configuration .ebextensions and redeployment.

 packages: yum: libjpeg-turbo-devel: [] libpng-devel: [] freetype-devel: [] container_commands: ... 05_uninstall_pil: command: "source /opt/python/run/venv/bin/activate && yes | pip uninstall Pillow" 06_reinstall_pil: command: "source /opt/python/run/venv/bin/activate && yes | pip install Pillow --no-cache-dir" 
+8
source share

As suggested, I included SSHed in the instance again and reinstalled Pillow via pip (/ opt / python / run / venv / bin / pip), but not before I made sure libjpeg-devel was in the environment before Pillow.

I ran selftest.py and 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.

+3
source share

All Articles