2

My PIL library works fine for a while, but now i get this exception everywhere, how to fix this?

f = "/media/bighdd/1.jpg"
from PIL import Image
im = Image.open(f)
im.thumbnail('50x50')
im.save('/media/bighdd/2.jpg')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1437, in save
    save_handler(self, fp, filename)
  File "/usr/local/lib/python2.7/dist-packages/PIL/JpegImagePlugin.py", line 471, in _save
    ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 494, in _save
    for e, b, o, a in tile:
ValueError: Not a valid numbers of quantization tables. Should be between 2 and 4.
Evg
  • 2,978
  • 5
  • 43
  • 58
  • You should go to line 494 in ImageFile.py and determine where the error is being thrown by adding your own logging; or something. This could be a fun exercise in debugging a major package! ...or you could just re-download the binaries and install again. – blakev Sep 17 '13 at 17:45

2 Answers2

2

check that you import Image in this way:

from PIL import Image

I had the same error when in my code was

import Image

and this tiny change make things roll

Un Peu
  • 131
  • 3
  • 13
0

Are you using a virtualenv? In my case, the error was in the sorl library, in the get_thumbnail method call. Therefor, I was not supposed to change code in the library, which is a bad practice. I figured out that sorl was using the PIL library installed in my web hosting provider's system, and not the one in my virtualenv. So, I added my virtualenv's site-packages folder (normally with the form "/home/user/.virtualenvs/virtualenv-name/lib/python2.7/site-packages") to the beginning of the sys.path, and the problem was solved, since the version of PIL and sorl installed in the virtualenv are newer than the ones installed in the system, and had this problem solved. I hope this can be useful!

Throoze
  • 3,988
  • 8
  • 45
  • 67
  • BTW, in my virtualenv I have installed: `sorl-thumbnail==11.12`, `PIL==1.1.7` and `Pillow==2.1.0`. – Throoze Jan 17 '14 at 04:18