user2990490
user2990490

Reputation: 21

"decoder jpeg not available" with Django on Elastic beanstalk

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:

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:

Upvotes: 2

Views: 1011

Answers (3)

pX0r
pX0r

Reputation: 1570

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

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

Hope this helps someone.
Cheers!

Upvotes: 0

Rohit Banga
Rohit Banga

Reputation: 18916

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

Upvotes: 2

pchiquet
pchiquet

Reputation: 3187

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

Upvotes: 0

Related Questions