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