How to solve IOError:broken data stream when reading image file?

Joseph Lafuente picture Joseph Lafuente · Oct 4, 2011 · Viewed 7k times · Source

Im working under Ubuntu 11.04. I'm trying to work with PIL in my Django project. Sadly PIL cannot load my image.

Here is the PIL setup summary:

PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
              [GCC 4.5.2]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
--------------------------------------------------------------------

I tried coding in python shell and it returns the error when I called load() function:

>>> import PIL
>>> import Image
>>> import _imaging
>>> i = Image.open("someimage.jpg")
>>> i
<JpegImagePlugin.JpegImageFile image mode=RGB size=600x599 at 0x9646C0C>
>>> i.load()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/joseph/Desktop/thesis/env/lib/python2.7/site-packages/PIL/ImageFile.py", line 215, in load
raise_ioerror(e)
File "/home/joseph/Desktop/thesis/env/lib/python2.7/site-packages/PIL/ImageFile.py", line 52, in raise_ioerror
raise IOError(message + " when reading image file")
IOError: broken data stream when reading image file

I am also working in a Virtual Environment, I am having problems with uploading jpeg image on my Django project. PNG works fine but it rejects JPEG

Answer

Joseph Lafuente picture Joseph Lafuente · Oct 6, 2011
sudo apt-get install libjpeg8-dev

rebuild PIL and install again.