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



 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下的解决方案,求解答

python pil

nono马 8 years, 9 months ago

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

空虚的愚人 answered 8 years, 9 months ago

Your Answer