3

I'm trying to install PIL on Snow Leopard, using Python 2.6.1, GCC 4.2.1, PIL 1.1.7, and have tried with both libjpeg6b and libjpeg7 -- nothing works. I've cleared out every trace of libjpeg/pil/zlib from fink, tried various compiler options, etc. and used http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/ and http:// www.brambraakman.com/blog/comments/installing_pil_in_snow_leopard_jpeg_resync_to_restart_error/ (not a link because StOv only lets me post one...)

4 bits of potentially useful information:

OTOOL does not show libjpeg as a dependency

otool -L /Library/Python/2.6/site-packages/PIL/_imaging.so
/Library/Python/2.6/site-packages/PIL/_imaging.so:
 /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

I get these weird compiler messages

i686-apple-darwin10-gcc-4.2.1: -framework: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: Tcl: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: -framework: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: Tk: linker input file unused because linking not done
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include/freetype2 -I/sw/include -I/opt/local/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c Tk/tkImaging.c -o build/temp.macosx-10.6-universal-2.6/Tk/tkImaging.o -framework Tcl -framework Tk
In file included from /System/Library/Frameworks/Tk.framework/Headers/tk.h:78,
                 from Tk/tkImaging.c:51:

selftest.py fails because of _imagingmath (after I used the second link given above, before it too failed due to _imaging)

Themistocles:Imaging-1.1.7 me$ python selftest.py 
Traceback (most recent call last):
  File "selftest.py", line 11, in <module>
    from PIL import ImageMath
  File "./PIL/ImageMath.py", line 19, in <module>
    import _imagingmath
ImportError: No module named _imagingmath

Anything but selftest.py fails because of _imaging

>>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
  Referenced from: /Library/Python/2.6/site-packages/PIL/_imaging.so
  Expected in: flat namespace
 in /Library/Python/2.6/site-packages/PIL/_imaging.so

Please, please help! This is getting ridiculous. I'd even be happy to be able to compile PIL sans jpeg support at this point!

3 Answers3

5

I recently wrote an article on how to get PIL, django, libjpeg to work nicely alongside Snow Leopard

http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/

I'll copy it in here for you too.

If you don’t have this download it first.

http://www.ijg.org/files/jpegsrc.v7.tar.gz

go into your shell environment and untar by running the following

tar -zxvf jpegsrc.v7.tar.gz
cd jpeg-7

then run

sudo make clean
sudo CC="gcc -arch i386”"./configure --enable-shared --enable-static
sudo make
sudo make install

Next get PIL and untar it

http://effbot.org/downloads/Imaging-1.1.6.tar.gz
tar -zxvf Imaging-1.1.6.tar.gz
cd Imaging-1.1.6

If you already have PIL I would recommend running

sudo rm -Rf build

to clean any existing builds, this has caused me loads of errors and gray hairs!

in your settings.py file run find JPEG_ROOT

amend it so it looks as follows

JPEG_ROOT = libinclude(“/usr/local”)

Next move onto the build

sudo python setup.py build

if libjpeg is successfully installed you should be able to run python selftest.py without any errors relating to “jpeg”

sudo python setup.py install

if all has worked successfully you should be able to enter your python interpreter by executing python in your command line and also do the following:

import PIL
import Image
import _imaging

without any errors.

Just to triple check I have a simple jpeg on my desktop.

image = Image.open(“/Users/MyName/Desktop/myimage.jpeg”)
image.save(“/Users/MyName/Desktop/test.jpeg”)

should work without errors

ApPeL
  • 4,801
  • 9
  • 47
  • 84
  • 1
    +11111!!! following the instructions above (taking care to wipe out pre-existing libjpeg install first) was the final successful solution for me after many failures. For others I also got the `ImportError: No module named _imagingmath` when running selftest.py, but it doesn't seem to matter because at last I can `import _imaging` without the _jpeg_resync_to_restart error – Anentropic Feb 29 '12 at 20:47
  • argh, no! I still get `IOError: decoder jpeg not available` ...tearing my hair out! – Anentropic Feb 29 '12 at 20:51
  • 1
    ah yes! I forgot to do the `sudo make install` command on libjpeg, started again froms scratch and it really works now. sanity restored! – Anentropic Feb 29 '12 at 21:04
  • Now it complains about `libz`. I worked around by disabling the lines `libs.append(feature.zlib)` and `defs.append(("HAVE_LIBZ", None))` at setup.py . So sad. – alanjds Feb 16 '13 at 08:41
1

Download macport:

http://www.macports.org/install.php

Then use it for pil:

http://trac.macports.org/browser/trunk/dports/python/py-pil/Portfile

I also had a lot of trouble with this, but port managed.

eruciform
  • 7,680
  • 1
  • 35
  • 47
  • Should I remove the copies of libjpeg/PIL that I've got installed? – Harkonnen Jama Jul 11 '10 at 21:23
  • Hang on, does macports want to install its own Python, or will it play nice with the system one? – Harkonnen Jama Jul 11 '10 at 21:25
  • i had already installed a newer python when i ran it, so i'm not completely sure. it may want to reinstall a bunch of things that fink already has, i've never used the two in conjunction. – eruciform Jul 11 '10 at 21:32
  • @Harkonnen: MacPorts will want to install its own python - Python 2.4 at that! If you're trying to get it to work with your system's Python, you can try copying it over manually to your Python's site-packages directory (not sure if that will work in your case), or you might just peek inside the Portfile to see if they've made any patches to get it to build. It should also give you an idea of what version of libjpeg to shoot for. – Owen S. Jul 11 '10 at 22:34
  • Macports insists on installing its own Python, which I really don't want...is there a way around that? – Harkonnen Jama Jul 11 '10 at 22:43
0

I've always gotten several screens worth of gcc errors when trying to install PIL. At some point I got something working (perhaps via MacPorts), so now my solution is to copy it to the appropriate site-packages (e.g. inside a new virtualenv).

I just posted it here: http://blogmaker.com/PIL-1.1.6-for-MacOSX-10.5-Leopard.zip

Works for me; I have no idea whether it will work for anyone else! Feel free to contact me with suggestions. And, let me know if there's a better place I should post it. PIL is both very cool and a royal hassle; it would be nice to have a definitive place for support. There are other PIL-related issues that I never solved.

Scott Lawton
  • 596
  • 6
  • 11
  • Update for people who find this post via a search: there's also a fork of PIL called Pillow that is aimed at being easier to install. See http://pypi.python.org/pypi/Pillow/ (I haven't tested it, but will next time I have to install.) – Scott Lawton Oct 13 '12 at 03:13