Python &引用;解码器jpeg不可用“;AWS弹性豆茎枕
我在AWS Elastic Beanstalk下处理Python上的jpeg文件时遇到一些问题 我在.ebextensions/python.config文件中有以下内容:Python &引用;解码器jpeg不可用“;AWS弹性豆茎枕,python,amazon-web-services,python-imaging-library,amazon-elastic-beanstalk,pillow,Python,Amazon Web Services,Python Imaging Library,Amazon Elastic Beanstalk,Pillow,我在AWS Elastic Beanstalk下处理Python上的jpeg文件时遇到一些问题 我在.ebextensions/python.config文件中有以下内容: packages: yum: libjpeg-turbo-devel: [] libpng-devel: [] freetype-devel: [] ... 所以我相信我已经安装了libjpeg并可以正常工作(我尝试了libjpeg-devel,但yum找不到这个包) 此外,我在我的requirements.
packages:
yum:
libjpeg-turbo-devel: []
libpng-devel: []
freetype-devel: []
...
所以我相信我已经安装了libjpeg并可以正常工作(我尝试了libjpeg-devel,但yum找不到这个包)
此外,我在我的requirements.txt上有以下内容:
Pillow==2.5.1
...
所以我相信我已经安装了枕头并在我的环境中工作
然后,因为我有枕头和libjpeg,所以我尝试在Python脚本中使用PIL.Image并保存到文件中。像这样:
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')
但是,当我尝试在Elastic Beanstalk的实例上运行它时,当它调用.save()方法时,异常“decoder jpeg not available”
如果我使用SSH连接到实例中,它就可以正常工作,而且我已经尝试过重建环境
我做错了什么
更新:
正如所建议的,我再次下载到实例中,并通过pip(/opt/python/run/venv/bin/pip)重新安装了Pillow,这是在我确定libjpeg-devel在Pillow之前就已经在环境中了
我运行了selftest.py,它确认了我对jpeg的支持。所以,在最后一次尝试中,我在Elastic Beanstalk界面上选择了“重启应用服务器”。成功了
谢谢大家。正如建议的那样,我再次下载到该实例中,并通过pip(/opt/python/run/venv/bin/pip)重新安装了Pillow,而在此之前,我还没有确定Pillow之前的环境中有libjpeg-devel
我运行了selftest.py,它确认了我对jpeg的支持。所以,在最后一次尝试中,我在Elastic Beanstalk界面上选择了“重启应用服务器”。它起作用了。根据来自的一般建议,我通过在.ebextensions配置中添加以下内容并重新部署解决了这个问题
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"
您是在枕头之前还是之后安装了libjpeg?我的经验是,安装枕头时libjpeg必须存在。请尝试卸载pillow,并在确定已安装libjpeg后再次安装。在处理requirements.txt之前已安装程序包。您能否快照日志以查看日志中是否出现任何错误@佩德罗艾夫斯:请在下面的答案框中添加你的答案好吗?这样就不会出现未回答的问题,其他人可以更快地找到解决方案。@Hugo Sure。完成了。