1

I'm facing an strange problem with PIL. Whenever I am compiling the following code with python everything is ok:

from PIL import Image
file=Image.open("si.jpg") 
file2=file.convert("L")
pix = file2.load()
print pix
colsize,rowsize=file2.size
for i in range(rowsize):
    for j in range(colsize): 
        if pix[j,i]>250:
            pix[j,i]=250
file2.save("ci2.pgm")

But when I compile the above code in SageMath Notebook, it gives an error “IOError: decoder jpeg not available”. Here is the scrrenshot :
enter image description here I have found a similar problem here, but these solution does not work for me. My OS is Ubuntu 16.04 (32bit). The image link :enter image description here) I want to get solution for SageMath. How do I solve this issue?

Community
  • 1
  • 1
MKS
  • 199
  • 1
  • 8

1 Answers1

1

It seems your version of the Python package "Pillow" (the Python Image Library) is missing the decoder for jpg.

To install it, quit Sage, and in a terminal, run the following:

$ sudo apt-get install libjpeg-dev
$ sage --pip install --no-cache-dir -I pillow

Then restart Sage and try running your code again.

Samuel Lelièvre
  • 3,212
  • 1
  • 14
  • 27
  • 1
    Note that if you run `sage -f pillow`, then jpg support will not be compiled, because it is disabled in the Sage installation file for pillow. Using `sage --pip install ... pillow` should work, though. – John Palmieri Aug 22 '18 at 03:12