Ped*_*ves 8 python amazon-web-services python-imaging-library pillow amazon-elastic-beanstalk
我在AWS Elastic Beanstalk下处理Python上的jpeg文件时遇到了一些麻烦.
我在.ebextensions/python.config文件中有这个:
packages:
yum:
libjpeg-turbo-devel: []
libpng-devel: []
freetype-devel: []
...
Run Code Online (Sandbox Code Playgroud)
所以我相信我已经安装了libjpeg并且正在工作(我试过libjpeg-devel,但是yum找不到这个包).
另外,我在我的requirements.txt上有这个:
Pillow==2.5.1
...
Run Code Online (Sandbox Code Playgroud)
所以我相信我已经安装了Pillow并在我的环境中工作.
然后,因为我有Pillow和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')
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在Elastic Beanstalk的实例上运行它时,异常"解码器jpeg不可用"时调用.save()方法.
如果我SSH到我的实例,它工作得很好,我已经尝试重建环境.
我究竟做错了什么?
更新:
正如所建议的那样,我再次连接到实例并通过pip(/ opt/python/run/venv/bin/pip)重新安装Pillow,而不是在我确定libjpeg-devel在Pillow之前的环境之前.
我跑了selftest.py并确认我支持jpeg.所以,在最后一次尝试中,我去了Elastic Beanstalk界面上的"重启App Server".有效.
谢谢你们.
根据这里的一般建议,我通过在.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"
Run Code Online (Sandbox Code Playgroud)
按照建议,我再次通过 SSH 连接到实例并通过 pip (/opt/python/run/venv/bin/pip) 重新安装 Pillow,在此之前我已确定 libjpeg-devel 在 Pillow 之前的环境中。
我运行 selftest.py 并确认我支持 jpeg。因此,在最后一次尝试中,我转到 Elastic Beanstalk 界面上的“重新启动应用程序服务器”。有效。