[Image-SIG] broken data stream when reading image file

Fredrik Lundh fredrik at pythonware.com
Sat May 29 14:51:25 CEST 2010

The confusion here is that setup.py reports what it identified, and
what parts it told the distutils system to build (expecting distutils
to yell if something went wrong), while the selftest.py reports what
it actually found for the PIL build it managed to import.  Usually,
having the first one build things successfully means that the second
one will be able to test them successfully, but sometimes, things go
wrong on the way (and that seems to be especially likely if you have
debris around from earlier build attempts).

In your case, when you run the test, the following happens:

   1. imports the PIL.Image.py module (which succeeds)
      this imports some other components, including _imaging (succeeds)
   2. imports _imaging again, explicitly (FAILS, which results in the
PIL CORE complaint)
   3. checks that the _imaging module imported by Image.py has a JPEG
codec (succeeds)
   4. checks that the _imaging module imported by Image.py has a ZLIB
codec (succeeds)
   5. checks for a few more support modules, by importing them
explicitly (FAILS)
   6. tries to use the JPEG module to read a sample file (FAILS)

My guess is that the _imaging.so module built by setup.py doesn't
work, for some reason, and that Python then goes ahead and imports the
one under /opt/local/Library/Frameworks/Python.framework/... instead,
which can be imported, but has a broken JPEG module (either that, or
the sample file is damaged).  You can check this by doing:

   $ python
   >>> import sys
   >>> sys.path.insert(0, ".")
   >>> from PIL import Image
   >>> Image.core
   ... this will tell you from where PIL pulled the _imaging module ...
   >>> from PIL import _imaging
   >>> _imaging

Let us know if this results in any errors.  Also make sure that the
Image.core output is the module you built yourself.

To check if the sample file is ok, open it in some other program.


On Sat, May 29, 2010 at 4:03 AM, Simon Mosk-Aoyama <simonsez at gmail.com> wrote:
> Hello,
> I'm trying to get PIL to work on my OS X 10.6 box, and unfortunately
> have ran into some trouble with the JPEG CODEC.
> I installed the library from port, but when I try to run my
> application and read a JPEG I get the following error:
> broken data stream when reading image file
> Tracing this back to PIL I went to install PIL manually, which seems to succeed:
> --------------------------------------------------------------------
> --------------------------------------------------------------------
> version       1.1.7
> platform      darwin 2.6.5 (r265:79063, Apr 17 2010, 18:49:39)
>              [GCC 4.2.1 (Apple Inc. build 5659)]
> --------------------------------------------------------------------
> --- TKINTER support available
> --- JPEG support available
> --- ZLIB (PNG/ZIP) support available
> --- FREETYPE2 support available
> --- LITTLECMS support available
> --------------------------------------------------------------------
> And yet when I run python selftest.py I get:
> --------------------------------------------------------------------
> --------------------------------------------------------------------
> Python modules loaded from ./PIL
> Binary modules loaded from
> /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL
> --------------------------------------------------------------------
> *** PIL CORE support not installed
> *** TKINTER support not installed
> --- JPEG support ok
> --- ZLIB (PNG/ZIP) support ok
> *** FREETYPE2 support not installed
> *** LITTLECMS support not installed
> --------------------------------------------------------------------
> Running selftest:
> *****************************************************************
> Failure in example:
> try:
>  _info(Image.open(os.path.join(ROOT, "Images/lena.jpg")))
> except IOError, v:
>  print v
> from line #24 of selftest.testimage
> Expected: ('JPEG', 'RGB', (128, 128))
> Got: broken data stream when reading image file
> 1 items had failures:
>   1 of  57 in selftest.testimage
> ***Test Failed*** 1 failures.
> *** 1 tests of 57 failed.
> So far searches on the error message haven't turned up anything. I'm a
> little concerned about the PIL_CORE not installed message, should I
> be?
> Any ideas?
> Thanks
> -Simon
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig

More information about the Image-SIG mailing list