Python 保存裁剪图像时出现奇怪的枕头异常
我们有以下代码:Python 保存裁剪图像时出现奇怪的枕头异常,python,python-2.7,python-imaging-library,Python,Python 2.7,Python Imaging Library,我们有以下代码: img = Image.open(FileSystemStorage().path(relpath)) coords = [ cd['crop_start_x'], cd['crop_start_y'], cd['crop_end_x'], cd['crop_end_y'] ] cropped_img = img.crop(coords) cropped_path =
img = Image.open(FileSystemStorage().path(relpath))
coords = [
cd['crop_start_x'],
cd['crop_start_y'],
cd['crop_end_x'],
cd['crop_end_y']
]
cropped_img = img.crop(coords)
cropped_path = "%s-cropped%s" % os.path.splitext(relpath)
tasks.delete_temporary_file.delay(fss.path(relpath))
cropped_img.save(fss.path(cropped_path))
当试图保存裁剪后的图像时,我们会得到一个奇怪的“不是有效数量的量化表。应该在1到4之间。”异常,仅在我们的一个环境中。
最奇怪的是,即使裁剪或图像没有改变,代码有时也会工作
有人知道这件事吗
我们使用的是Pilly 2.8.1、python 2.7.6和Ubuntu服务器12.04基本上,问题源于其中一个应用服务器中的PIL安装冲突。很难找到,因为它们隐藏在负载平衡器后面,所以有时会出现错误 当我们在控制台上发布
pipfreeze
时,我们发现在其中一台服务器上同时安装了PIL和Pillow
在移除它们并重新安装枕头后,我们解决了问题
我只想说清楚:
pip uninstall PIL
pip uninstall Pillow
pip install Pillow
然后,只需重新启动web服务器
如其他人所述,另一个可能的原因是使用:
import Image
该声明仅适用于PIL,应避免使用。
我们应该始终使用:
from PIL import Image
那个环境有什么不同吗?我们已经检查过了。。从操作系统包到枕头版本,尝试过枕头重新安装等等。。。仍然没有luckDo您有任何可能与Pillow冲突的PIL安装?您是如何导入类映像的?当插入式替换采用与现有模块相同的包名时,会发生这种情况:\