ERROR: Broken data stream while reading image file (TrueType libjpeg and PIL fonts on OS X)

I run OS X 10.6.7, Python 2.6 and write a small wxPython application that uses PIL to control the image and add some text to it.

After a few configuration problems, trying to get the PIL running with libjpeg and PIL, I followed the instructions on this site .

When I run python setup.py build_ext -i (from inside the Imaging-1.1.7 folder) I get:

 -------------------------------------------------------------------- PIL 1.1.7 SETUP SUMMARY -------------------------------------------------------------------- version 1.1.7 platform darwin 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] -------------------------------------------------------------------- --- TKINTER support available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available --- LITTLECMS support available -------------------------------------------------------------------- 

Also, by running python selftest.py in the Imaging-1.1.7 installation folder, I get:

 -------------------------------------------------------------------- PIL 1.1.7 TEST SUMMARY -------------------------------------------------------------------- Python modules loaded from ./PIL Binary modules loaded from ./PIL -------------------------------------------------------------------- --- PIL CORE support ok --- TKINTER support ok --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE2 support ok --- LITTLECMS support ok -------------------------------------------------------------------- Running selftest: --- 57 tests passed. 

However, when rendering my first PIL image in my own code, I still get:

 File "/Library/Python/2.6/site-packages/PIL/Image.py", line 1290, in resize self.load() File "/Library/Python/2.6/site-packages/PIL/ImageFile.py", line 215, in load raise_ioerror(e) File "/Library/Python/2.6/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 do not seem to understand what to do next. Any ideas? The code causing this failure is as follows:

 try: self.img = self.img.resize((self.screenwidth, self.screenheight), Image.ANTIALIAS) except IOError, e: print "Error resizing: " + str(e) self.img = self.img.resize((self.screenwidth, self.screenheight)) raise 
+4
source share
3 answers

You should consider removing PIL and following the instructions on this website - http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/

In particular, it seems like you want to make sure libjpeg is in version 6b , not 8c (see below)


I can reproduce this using Mac OS X 10.5 using macports

This is related to another question: How to solve IOError: a broken data stream while reading an image file?

The answer there indicates that the error may have something to do with libjpeg

As far as I can tell, the error seems to be caused by advanced incompatibility with libjpeg v8c.

I cannot determine what exactly causes this; all I can say is that on many other systems that I use, they do not exhibit this behavior error (OS X 10.5 with fink, Redhat 5.2, Ubuntu 11.10 and 10.10), they all use libjpeg 6b. Only macports uses 8c, and macports is the only system I get this error on.

+2
source

I was able to use PIL with the homebrew package manager .

+1
source

I have the same error while reading a .jpg file with the updated Python environment and Sierra Mac OS. I found a quick workaround which is to convert all .jpg files to .png files. Hoping this can help someone else.

0
source

Source: https://habr.com/ru/post/921525/


All Articles