windows下使用PIL库提示 module' object has no attribute 'zip_decoder'

发布于 2022-09-01 17:19:48 字数 3402 浏览 15 评论 0

from PIL import Image, ImageDraw, ImageFont

def add_num(img):
    draw = ImageDraw.Draw(img)
    myfont = ImageFont.truetype('C:/windows/fonts/Arial.ttf', size=40)
    fillcolor = "#ff0000"
    width, height = img.size
    draw.text((width-40, 0), '99', font=myfont, fill=fillcolor)
    img.save('result.jpg','jpeg')

    return 0
if __name__ == '__main__':
    image = Image.open('image.jpg')
    add_num(image)

运行时提示错误:

Traceback (most recent call last):
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\ImageDraw.py", line 347, in Draw
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\Image.py", line 626, in __getattr__
AttributeError: getdraw

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\Image.py", line 411, in _getdecoder
AttributeError: 'module' object has no attribute 'zip_decoder'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "add_num.py", line 14, in <module>
    add_num(image)
  File "add_num.py", line 4, in add_num
    draw = ImageDraw.Draw(img)
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\ImageDraw.py", line 349, in Draw
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\ImageDraw.py", line 63, in __init__
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\ImageFile.py", line 196, in load
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\Image.py", line 415, in _getdecoder
OSError: decoder zip not available

python 版本:3.4.3,在win10上运行,vs2015
我如果调用PIL.Image 的show()方法时,会提示

Traceback (most recent call last):
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\Image.py", line 411, in _getdecoder
AttributeError: 'module' object has no attribute 'zip_decoder'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "load_data.py", line 6, in <module>
    iw.show()
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\Image.py", line 1742, in show
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\Image.py", line 2498, in _show
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\Image.py", line 2503, in _showxv
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\ImageShow.py", line 51, in show
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\ImageShow.py", line 77, in show
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\ImageShow.py", line 96, in show_image
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\ImageShow.py", line 92, in save_image
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\Image.py", line 575, in _dump
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\ImageFile.py", line 196, in load
  File "D:\Python34\lib\site-packages\pillow-3.0.0.dev0-py3.4-win32.egg\PIL\Image.py", line 415, in _getdecoder
OSError: decoder zip not available

自己尝试找了一下,发现没有在windows下的解决方案,求解答

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫雪独思 2022-09-08 17:19:48

问题已解决!
使用了评论中 依云 提到的Unofficial Windows Binaries版本,现在程序可以正常运行。
初学编程,在report bug上做的不好,希望能够谅解。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文