【发布时间】:2020-02-11 04:10:17
【问题描述】:
在python代码中,我需要处理webp图像。但是当我尝试用 python PIL 模块打开它时,我有一个错误:
OSError: cannot identify image file 'my_image.webp
我的深度学习映像是从 GCP Marketplace VM(tensorflow 映像)创建的,但 webp 格式似乎没有在枕头级别“激活”。
python默认支持webp格式吗? 我需要在 VM 上做什么/安装/导入才能使用 python PIL 打开 webp 图像?
我的python代码步骤:
>>>import PIL
>>>print(PIL.__version__)
6.0.0.post0
>>>from PIL import features
>>>print (features.check_module('webp'))
False
>>> PIL.Image.open('my_image.webp')
/usr/local/lib/python3.5/dist-packages/PIL/Image.py:2703: UserWarning: image file could not be identified because WEBP support not installed
warnings.warn(message)
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-4-99a62d35da67> in <module>
----> 1 PIL.Image.open('BATIMENT0000000045936174_flatRoof.webp')
/usr/local/lib/python3.5/dist-packages/PIL/Image.py in open(fp, mode)
2703 warnings.warn(message)
2704 raise IOError("cannot identify image file %r"
-> 2705 % (filename if filename else fp))
2706
2707 #
OSError: cannot identify image file 'my_image.webp'
【问题讨论】:
-
看起来这些步骤可以为枕头添加 webp 支持:
pip uninstall Pillow &&\ pip uninstall Pillow-SIMD &&\ sudo apt install libwebp-dev &&\ pip install Pillow-SIMD然后需要重新启动 jupyter 内核并且 PIL 能够读取 webp 图像
标签: python-imaging-library webp google-dl-platform