Python Pillow(更好的PIL)编码检查错误

4

我刚刚在虚拟环境中安装了Pillow包。具体操作如下:

from PIL import Image, ImageFont, ImageDraw
ImageFont.load_path('some_path')

我遇到了一个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/net/isilonP/public/rw/homes/cbl_adm/.virtualenvs/chembl_webservices/lib/python2.7/site-packages/PIL/ImageFont.py", line 264, in load_path
    if not isinstance(filename, "utf-8"):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

确实,如果您查看官方的Github存储库(https://github.com/python-imaging/Pillow/blob/master/PIL/ImageFont.py#L264),您可以看到这个结构:

if not isinstance(filename, "utf-8"):
    ...

我的问题是:如何用实际可行的东西替换它?

向项目提交错误报告?Pillow正在进行非常活跃的开发。 - Martijn Pieters
完成!https://github.com/python-imaging/Pillow/issues/304 - mnowotka
1个回答

2

有人忽略了对该方法进行测试;正确的调用方式是:

if not isinstance(filename, str):
    # ...

因为代码的其余部分会将它转换为Python 2和Python 3的str,所以需要这样做。我在IRC上与维护者交谈后提交了一个pull request。更新:补丁现已合并。

是的,在我推送之后才看到。乘坐火车旅行,联网和编码的机会时有时无。 :-) - Martijn Pieters

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接