这是我的代码:
from skimage import io,color
filename = io.imread("input00.jpg")
img = color.rgb2gray(filename,as_grey=True)
io.imshow(img)
io.show()
在第2行引发错误说:
AttributeError: 'builtin_function_or_method' object has no attribute 'iterkeys'
回溯:
Traceback (most recent call last):
File "readImg.py", line 2, in <module>
filename = io.imread("input00.jpg")
File "/Library/Python/2.7/site-packages/skimage/io/_io.py", line 97, in imread
img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
File "/Library/Python/2.7/site-packages/skimage/io/manage_plugins.py", line 209, in call_plugin
return func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9- intel.egg/matplotlib/pyplot.py", line 2198, in imread
return _imread(*args, **kwargs)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/image.py", line 1249, in imread
'more images' % list(six.iterkeys(handlers.keys)))
File "/Library/Python/2.7/site-packages/six-1.7.2-py2.7.egg/six.py", line 547, in iterkeys
return iter(d.iterkeys(**kw))
AttributeError: 'builtin_function_or_method' object has no attribute 'iterkeys'
答案 0 :(得分:6)
遇到了同样的问题。解决方法是安装Pillow(你可以从这里http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow)
答案 1 :(得分:0)
代码的相关位似乎是:
if ext not in handlers:
im = pilread(fname)
if im is None:
raise ValueError('Only know how to handle extensions: %s; '
'with PIL installed matplotlib can handle '
'more images' % list(six.iterkeys(handlers.keys)))
return im
所以我认为你面临两个问题。
(1)由于某种原因(可能没有枕头?)你无法处理jpg文件。
(2)matplotlib
中存在错误,因此错误信息未被打印出来,因为它有错误。 (!)
而不是
>>> list(six.iterkeys(handlers.keys))
Traceback (most recent call last):
File "<ipython-input-13-2e5e3ad4f63f>", line 1, in <module>
list(six.iterkeys(handlers.keys))
File "/usr/local/lib/python2.7/dist-packages/six.py", line 490, in iterkeys
return iter(getattr(d, _iterkeys)(**kw))
AttributeError: 'builtin_function_or_method' object has no attribute 'iterkeys'
他们应该使用
>>> list(six.iterkeys(handlers))
['png']
直接传递handlers
字典。
答案 2 :(得分:0)
我的项目中也会出现此问题。我的解决方案是首先删除Pillow sudo apt-get remove python-pil
;当然,如果你还没有安装Pillow,请首先安装它,然后测试),然后重新安装Pillow(sudo apt-get install python-pil
),问题解决了!