python - windows下使用PIL库提示 module' object has no attribute 'zip_decoder'
PHP中文网
PHP中文网 2017-04-17 15:48:52
0
1
1736
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下的解决方案,求解答

PHP中文网
PHP中文网

认证高级PHP讲师

全員に返信(1)
黄舟

問題は解決しました!
コメントで Evian が言及した非公式 Windows バイナリ バージョンを使用したところ、プログラムは正常に実行できるようになりました。
私はプログラミングの初心者で、バグを報告するのが苦手です。ご理解いただけると幸いです。

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート