I opened a picture with PIL, but when I tried to use split()
to split the channels I got following error:
AttributeError: 'NoneType' object has no attribute 'bands'
import Image
img = Image.open('IMG_0007.jpg')
img.split()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/blum/<ipython console> in <module>()
/usr/lib/python2.6/dist-packages/PIL/Image.pyc in split(self)
1495 "Split image into bands"
1496
-> 1497 if self.im.bands == 1:
1498 ims = [self.copy()]
1499 else:
AttributeError: 'NoneType' object has no attribute 'bands'
My problem was that PIL was not installed correctly. When trying to read a png I'd get that error. My compilation summary yielded
I then opted to "pip uninstall pil" and used the Synaptic Package Manager instead. That fixed it.
With googling I found this comment on SO, stating that PIL is sometimes 'lazy' and 'forgets' to load after opening. So you have to do it like this:
Please +1 also the original comment! This person did the real work.