PIL - Invalid number of quantization tables. Should be 2 to 4
My PIL library has been working fine for a while, but now I am getting this exception everywhere, how do I fix it?
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.
source to share
Are you using virtualenv
? In my case, the error was in the library sorl
in the method call get_thumbnail
. Therefore, I shouldn't have changed the code in the library, which is bad practice. I realized that I was sorl
using the library PIL
installed on my hosting provider system, not the one I have in virtualenv. So, I added my virtual packages folder for virtual sites (usually with a form "/home/user/.virtualenvs/virtualenv-name/lib/python2.7/site-packages"
) at the beginning sys.path
and the problem was resolved since the version PIL
and sorl
installed in virtualenv were different than the ones that were installed on the system and this problem was resolved. Hope this can be helpful!
source to share