2

I am developing a Django backend system on Elastic beanstalk.

When I upload JPEG image file, I get the error decoder jpeg not available. Uploading .png image files does not cause any problem.

Backend environment:

  • AWS beanstalk: 64bit Amazon Linux 2014.03 v1.0.4 running Python 2.7
  • python: 2.7
  • pip package list Django==1.6.5 Markdown==2.4.1 MySQL-python==1.2.5 Pillow==2.5.3 boto==2.30.0 django-filter==0.7 django-storages==1.1.8 djangorestframework==2.3.14 wsgiref==0.1.2

Source code causing error:

View

normalImage = NormalImage(image=image, userProfile=request.user.profile, category = category)
normalImage.save()

Model

class NormalImage(models.Model):
    userProfile = models.ForeignKey(UserProfile)
    height = models.PositiveIntegerField(editable=False)
    width = models.PositiveIntegerField(editable=False)
    image = models.ImageField(upload_to=rename_image_file, width_field='width', height_field='height')
    size = models.TextField()
    price = models.PositiveIntegerField()
    tags = models.ManyToManyField(Tag)
    category = models.ForeignKey(Category)
    created_datetime = models.DateTimeField(auto_now_add=True)

def __init__(self, *args, **kwargs):
    super(NormalImage,self).__init__(*args, **kwargs)
    if not self.id:
        self.size = Size.determineSizeDescription(anWidth=self.width, aHeight=self.height)
        self.price = Size.determinePrice(anWidth=self.width, aHeight=self.height)

def get_created_datetime_str(self):
    return self.created_datetime.strftime('%Y-%m-%d %H:%M:%S')

def get_image_url(self):
    return 'http://photocoapi-env-x2ezvferc7.elasticbeanstalk.com/images/' + str(self.id) + '/'

Error code:

IOError at /me/requests/ decoder jpeg not available Request Method: GET Request URL:
http://photoco-env-z5cnmns3pe.elasticbeanstalk.com/me/requests/ Django Version: 1.6.5 Exception Type: IOError Exception Value: decoder jpeg not available Exception Location: /opt/python/run/venv/lib/python2.7/site-packages/PIL/Image.py in _getdecoder, line 413 Python Executable: /opt/python/run/venv/bin/python Python Version: 2.7.5 Python Path: ['/opt/python/run/venv/lib/python2.7/site-packages', '/opt/python/current/app', '/opt/python/bundle/4/app', '/opt/python/run/baselinenv/lib64/python27.zip', '/opt/python/run/baselinenv/lib64/python2.7', '/opt/python/run/baselinenv/lib64/python2.7/plat-linux2', '/opt/python/run/baselinenv/lib64/python2.7/lib-tk', '/opt/python/run/baselinenv/lib64/python2.7/lib-old', '/opt/python/run/baselinenv/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7', '/usr/lib/python2.7', '/opt/python/run/baselinenv/lib/python2.7/site-packages']

What I've tried to solve this problem:

  • I connected to beanstalk server via SSH and installed below libraries by using yum
  • yum: libjpeg-devel,zlib-devel, freetype-devel

    • and then make symbolic link

      $ sudo ln -s /usr/lib64/libjpeg.so /usr/lib $ sudo ln -s /usr/lib64/zlib.so /usr/lib $ sudo ln -s /usr/lib64/freetype.so /usr/lib

Zulu
  • 8,765
  • 9
  • 49
  • 56

3 Answers3

2

You can include a file called "requirements.txt" in your app source with all the required dependencies and AWS Elastic Beanstalk will install the dependencies for you.

You can use ebextensions to install yum packages. Create a file called .ebextensions/01-yum.config in your app source and put the following contents in it.

packages: 
  yum:
    libjpeg-devel: [] 
    <another-package>: []

This file is in YAML format so indentation is important.

Read more about pacakges section of ebextensions here:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-packages

Here is a tutorial on using requirements.txt with Elastic Beanstalk.

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_python_console.html

Rohit Banga
  • 18,458
  • 31
  • 113
  • 191
  • I have the same problem, and adding the ebextension didn't fix it. In my logs it shows that yum installed libjpeg: Sep 30 19:00:27 Updated: libjpeg-turbo-1.2.1-3.3.amzn1.x86_64 Sep 30 19:00:27 Installed: libjpeg-turbo-devel-1.2.1-3.3.amzn1.x86_64 – Patrick Yan Sep 30 '14 at 20:01
0

The dependencies to support JPEG images must be installed BEFORE you install Pillow with pip (the python library used to decode images).

So you should try to:

  • uninstall Pillow:

    pip uninstall pillow

  • install jpeg libraries:

    yum install libjpeg-devel

  • reinstall pillow:

    pip install pillow

pchiquet
  • 3,097
  • 1
  • 13
  • 15
  • First of all, thank you for your answering. I actually did this several times. I tried removing pillow and installing libjpeg/pillow again but it was same. So, I wrote this question here whether I missed some properties of AWS beanstalk. For example,the Amazon Linux I am using now does not support these package normally in comparison with the other linux systems. – user2990490 Sep 03 '14 at 10:01
  • Ok. Sorry but I don't have any experience with AWS beanstalk. Did you install 'python-devel' yum package? You could also try to edit setup.cfg to specify the jpeg library location and run "python setup.py install" manually to install Pillow (as explained here http://pillow.readthedocs.org/en/latest/installation.html#simple-installation) – pchiquet Sep 03 '14 at 11:38
0

yum could not find libjpeg-devel. But this worked for me:

packages: 
  yum:
    libjpeg-turbo-devel: []

Hope this helps someone.
Cheers!

pX0r
  • 1,472
  • 12
  • 14