【问题标题】:Can't find method in a package在包中找不到方法
【发布时间】:2021-10-26 07:20:06
【问题描述】:
运行时抛出以下代码
AttributeError: module 'PIL.ImageChops' has no attribute 'overlay'
错误。
from PIL import Image, ImageChops
import matplotlib.pylab as plt
im1= Image.open(r'.\white.jpg')
im2= Image.open(r'.\green.jpg')
result = ImageChops.overlay(im1, im2)
plt.imshow(result)
根据参考应该有这个方法:
https://pillow.readthedocs.io/en/stable/reference/ImageChops.html。
我该如何纠正?
【问题讨论】:
标签:
python
image
image-processing
graphics
signal-processing
【解决方案1】:
检查您的 Pillow 版本。它必须 >= 7.1.0,如 release notes:
新频道运营
添加了三个新的通道操作:soft_light(),
hard_light() 和 overlay()。
通过python3 -m pip install Pillow==7.1 或更高版本更新。
使用 7.0
>>> from PIL import ImageChops
>>> ImageChops.overlay
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'PIL.ImageChops' has no attribute 'overlay'
使用 7.1(或更高版本)
>>> from PIL import ImageChops
>>> ImageChops.overlay
<function overlay at 0x7f766112ff70>