Reputation: 21
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:
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
Upvotes: 2
Views: 1011
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
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:
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
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