在包中找不到方法
Can't find method in a package
下面的代码当 运行 抛出
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。
我该如何更正它?
检查您的 Pillow 版本。它必须是 >= 7.1.0,如 release notes:
New channel operations
Three new channel operations have been added: soft_light(),
hard_light() and 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>
下面的代码当 运行 抛出
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。 我该如何更正它?
检查您的 Pillow 版本。它必须是 >= 7.1.0,如 release notes:
New channel operations
Three new channel operations have been added: soft_light(), hard_light() and
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>