Rich Atkinson

Rich Atkinson's Personal Blog

libjpeg and Python Imaging (PIL) on Snow Leopard

EDIT: These packages work a treat:

Sometimes OSX could learn a trick from Linux; a great example is package management.

Mac ports isn’t bad but it’s not a patch on archlinux’s AUR for simplicity, and Ubuntu is onto a really good thing with APT.

Installing Python Imaging (PIL) with Jpeg support on Snow Leopard isn’t obvious. For anyone struggling with it, here’s a solution:

1. Download the source from

2. Extract, configure, make:

tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
cp /usr/share/libtool/config/config.sub .
cp /usr/share/libtool/config/config.guess .
./configure --enable-shared --enable-static

3. You may need to create the following directories:

sudo mkdir -p /usr/local/include
sudo mkdir -p /usr/local/lib
sudo mkdir -p /usr/local/man/man1

4. Now you can install it as usual.

sudo make install

5. If you want to freetype support, do that now.

6. Finally, you can install PIL. Be sure to activate any vitualenv now if you don’t want to install PIL into the system site-packages.

pip install

At least the native Python 2.6 on Snow Leopard works great, and this wasn’t nearly as painfull as installing PIL on Cygwin!

Written by Rich Atkinson

September 5, 2009 at 10:05 pm

Posted in Python

33 Responses

Subscribe to comments with RSS.

  1. Thanks for that, it saved me some head scratching. One thing though, after “make” I had to do “sudo make install” before the Imaging module would give me the thumbs up for jpeg support.

    Jamie C

    September 8, 2009 at 6:00 am

  2. To get freetype support as well as jpeg support with PIL I had to download freetype-2.3.9 ( ) . Installing was quite painless and easy ( extract, configure, make, sudo make install ).

    I just thought I’d post this here as others may benefit from this.


    Jamie C.

    Jamie C

    September 9, 2009 at 8:01 pm

  3. @jamie. Yep. You’re right. I’ll edit the post to add the ‘make install’.

    And thanks for the note on freetype.

    Rich Atkinson

    September 11, 2009 at 12:36 am

  4. Can you import _imaging from PIL?

    I get a “Symbol not found” error:

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

    Joe K

    September 16, 2009 at 7:17 am

  5. Odd, I’m not having the same success you experience. I’m using a clean install of Snow Leopard and I’ve installed Python 2.6.2 (replacing the default 2.6.1 which is pre-installed). I seem to be getting errors from gcc; pip log here:

    Any thoughts?

    Mike Lawrence

    September 17, 2009 at 4:28 am

  6. When I am configuring libjpeg on Snow Leopard based on following your above procedure I’m seeing the following output near the end of configure,

    checking for ld used by GCC… /usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld
    checking if the linker (/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld) is GNU ld… no
    checking whether the linker (/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld) supports shared libraries… no
    checking for BSD-compatible nm… /usr/bin/nm
    checking command to parse /usr/bin/nm output… no
    checking how to hardcode library paths into programs… unsupported
    checking for /usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld option to reload object files… -r
    checking dynamic linker characteristics… no
    checking if libtool supports shared libraries… no
    checking whether to build shared libraries… no
    checking whether to build static libraries… yes

    Ultimately the problem I’m seeing is similar to others where trying to run the build or actually use PIL 1.1.6 results in an error:

    %python ./ build
    running build
    running build_py
    running build_ext
    — using frameworks at /System/Library/Frameworks
    version 1.1.6
    platform darwin 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
    [GCC 4.2.1 (Apple Inc. build 5646)]
    — TKINTER support ok
    — JPEG support ok
    — ZLIB (PNG/ZIP) support ok
    — FREETYPE2 support ok
    To check the build, run the script.
    running build_scripts
    clover% python ./
    *** The _imaging C module is not installed

    Digging into it a little further seems to show it is related to some undefined jpeg symbol (__jpeg_resync_to_restart),

    Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> from PIL import image
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: cannot import name image
    >>> from PIL import Image
    >>> import _imaging
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: dlopen(/Library/Python/2.6/site-packages/PIL/, 2): Symbol not found: _jpeg_resync_to_restart
    Referenced from: /Library/Python/2.6/site-packages/PIL/
    Expected in: flat namespace
    in /Library/Python/2.6/site-packages/PIL/

    I assume that is trying to load some libjpeg. However, I only see a libjpeg.a in /usr/local/lib (and since configure told me it couldn’t build a dynamic library when trying to build libjpeg) I guess it is no surprise. Is this a problem with the XCode build tool chain or something else? Any assistance would be greatly appreciated.

    Is the solution I need to figure out how to build a When you build libjpeg does the make install put a in /usr/local/lib?

    Scott Rankin

    Scott Rankin

    September 17, 2009 at 9:27 am

  7. Guys, I’m using the standard 2.6.1 from Apple, it’s worked perfectly for me. It doesn’t sound like that’s the issue though.

    You seem to have related problems, so there is more to this.

    Please report back here if you identify the fix.


    Rich Atkinson

    September 19, 2009 at 11:55 pm

  8. One thing I discovered is there is a version 7 of the libjpeg [1] that produces a libjpeg.dylib when I build it on my Snow Leopard system. I still can’t get PIL to behave properly though…

    I’m also using the stock python (as far as I know):
    % which python
    % python –version
    Python 2.6.1


    Scott Rankin

    September 23, 2009 at 6:01 am

  9. I got the same errors:

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


    September 23, 2009 at 11:31 am

  10. I’m getting the Symbol not found: _jpeg_resync_to_restart error as well.


    September 27, 2009 at 10:42 am

  11. I also have trouble with jpeg loading:

    >>> import _imaging
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: dlopen(/Library/Python/2.6/site-packages/PIL/, 2): Symbol not found: _jpeg_resync_to_restart

    I’ve tried installing libjpeg from ports, manual install, moving the libjpeg.dylib to various lib-dirs, setting DYLD_LIBRARY_PATH, recompiling Imaging… Also tried the exact steps in your post, but no luck.

    Snow leopard 10.6.1

    using gcc-4.2.1 (maybe this is the problem?)

    I’m also running in 64 bit mode, with python downgraded to 32-bit with ‘defaults write Prefer-32-Bit -bool yes’

    Will try to use a 32-bit kernel and see if that helps.



    September 30, 2009 at 10:40 pm

  12. Me. Three. It’s driving me nuts.

    Symbol not found: _jpeg_resync_to_restart

    Dave Merwin

    October 1, 2009 at 3:58 am

  13. I am getting the Symbol not found: _jpeg_resync_to_restart error as well. Any ideas what this is?


    October 3, 2009 at 12:25 am

  14. Running into the same _jpeg_resync_to_restart. I have tried every combination I can think of – compiling from source, fink, modifying and pointing the lib references manually. Argh!!!


    October 8, 2009 at 5:34 am

  15. me three, tried a bunch of different things. all same results and error


    October 13, 2009 at 10:02 am

  16. _jpeg_resync_to_restart is an indication you’re using the wrong jpeg library. PIL specifically says it needs jpeg-6b and you’re trying to use jpeg-7.

    Richard Jones

    October 13, 2009 at 2:59 pm

  17. So I had this same exact issue – _jpeg_resync_to_restart – and I solved it by following this post EXACTLY. Everything down to the virtual environment. It works flawlessly now for some reason although most of what he’s doing looks incredibly similar to the instructions here. He even references this blog post. Maybe someone that’s more knowledgeable than I am can divine why from the commands issued? Either way, give this a shot and see if it helps you.


    October 14, 2009 at 2:27 am

  18. The trick worked, thank you!

    If somebody has the problem after, try to do the following:
    otool -L /Library/Python/2.6/site-packages/PIL/

    It will list all dependencies.
    Check that libjpeg dependency points to a correct version you’ve just compiled. It should be:

    otool -L /Library/Python/2.6/site-packages/PIL/
    /usr/local/lib/libjpeg.62.dylib (compatibility version 63.0.0, current version 63.0.0)

    In my case it pointed to another library in /sw/local/lib. After deleting that version and rebuilding libjpeg again problem was solved forever :)

    Thanks again for author and hope my tip will help others to solve the problem too.


    October 16, 2009 at 5:12 am

  19. [...] проблемы частично описано здесь – качаем отсюда: [...]

  20. I also kept getting the “Symbol not found: _jpeg_resync_to_restart error” occurred when trying to import the imaging library. I finally got it working though.

    I described what was wrong with my installation here:

    Bram Braakman

    October 18, 2009 at 12:57 am

  21. I just solved my own version of the _jpeg_resync_to_restart error by installing the libjpeg v7 specifying the i386 architecture.

    I found, running one of the gcc command from the Imaging installation, that it made the following error : “libjpeg.a, file is not of required architecture”. So I googled a bit about that problem and found out that I should install the last version of libjpeg forcing the architecture.

    That’s what I did :
    1) After detaring the jpegsrc.v7.tar.gz file and running ./configure, I edited “Makefile” and found the line :
    and replaced it by :
    LDFLAGS = -arch i386 …
    Then make and make install.

    2) The lib was installed in /usr/local/lib so, back to the PIL installation : I detared “Imaging-1.1.6.tar.gz”, went into the new directory and edited “”. I replaced
    JPEG_ROOT = None
    JPEG_ROOT = “/usr/local/lib”

    3) Then I ran the “python build” and “python install” commands and it was working !

    Good luck !


    October 20, 2009 at 8:39 am

  22. Well, a small problem I solved before the big libjpeg problem :

    I could’nt manage to compile PIL (Imaging) with the last version of gcc (4.2). So I forced the compilation with gcc 4.0 by modifying the alias in /usr/bin

    WARNING: This has only been tested on my macbook pro running Snow Leopard. Please only follow this if you fully understand what it does.

    Forcing gcc to use 4.0 version :
    sudo rm /usr/bin/gcc
    sudo ln -s /usr/bin/gcc-4.0 /usr/bin/gcc

    Getting back to the 4.2 version of gcc :
    sudo rm /usr/bin/gcc
    sudo ln -s /usr/bin/gcc-4.2 /usr/bin/gcc


    October 20, 2009 at 8:46 am

  23. I am not very savvy UNIX user so I tried the steps as described . When I try to install I get this:

    SockMonkey:jpeg-6b norman$ sudo make install
    /usr/bin/install -c -m 644 jconfig.h /usr/local/include/jconfig.h
    /usr/bin/install -c -m 644 ./jpeglib.h /usr/local/include/jpeglib.h
    /usr/bin/install -c -m 644 ./jmorecfg.h /usr/local/include/jmorecfg.h
    /usr/bin/install -c -m 644 ./jerror.h /usr/local/include/jerror.h
    ./libtool –mode=install /usr/bin/install -c /usr/local/lib/
    /usr/bin/install -c /usr/local/lib/
    /usr/bin/install -c .libs/libjpeg.a /usr/local/lib/libjpeg.a
    ranlib /usr/local/lib/libjpeg.a
    chmod 644 /usr/local/lib/libjpeg.a
    Libraries have been installed in:

    To link against installed libraries in a given directory, LIBDIR,
    you must use the `-LLIBDIR’ flag during linking.

    You will also need to do one of the following:

    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and manual pages.
    ./libtool –mode=install /usr/bin/install -c cjpeg /usr/local/bin/cjpeg
    /usr/bin/install -c cjpeg /usr/local/bin/cjpeg
    install: /usr/local/bin/cjpeg: No such file or directory
    make: *** [install] Error 71
    SockMonkey:jpeg-6b norman$

    I appreciate any help.


    October 25, 2009 at 4:06 pm

  24. Thank you so much for publishing your solution to this.

    I tried doing the same myself but it did not work for me… actually I got into more trouble than the one I started from!

    Now building PIL creates MacOS 10.3 binaries

    $ sudo python2.5 build
    running build
    running build_py
    creating build/lib.macosx-10.3-i386-2.5
    copying PIL/ -> build/lib.macosx-10.3-i386-2.5
    copying PIL/ -> build/lib.macosx-10.3-i386-2.5
    copying PIL/ -> build/lib.macosx-10.3-i386-2.5

    and then fails with:

    cc1: error: unrecognized command line option “-Wno-long-double”

    I believe there may be confusion between Snow Leopard’s own Python and the one I installed from . I could not use the default one because I need my code to work on 2.5 . Any advice?


    October 25, 2009 at 10:10 pm

  25. I’ve been banging my head against the wall with this problem for a few days, but I finally got it worked out.

    First of all, my system is running python in 32bit mode with the same configuration as Stefan’s shown above.

    The key to fixing this was noticing that the libraries in /opt/local were always getting included and taking precedence over any other libjpeg libraries in the system (same with zlib). First I uninstalled all libjpeg related ports, and then installed libjpeg from here:

    The output from rebuilding PIL showed “ok” for support of all the functionality, but when I imported _imaging I got an error. But it was a new error! Symbol not found: _deflate.

    After discovering that it related to zlib, I uninstalled zlib from ports and freetype. I got zlib-1.2.3, which installed fine from source. Then I tried the newest version of freetype, but it wouldn’t build. The readme from PIL suggests freetype >= 2.1.3, so I chose 2.1.10. It built and installed fine from source.

    With all my libraries now in /usr/local, I rebuilt PIL (using libconfig(“/usr/local”) for jpeg, freetype and zlib), and everything went fine. Installed PIL, fired up python interpreter and imported _imaging, and no error!!!


    October 29, 2009 at 12:43 am

  26. In case it was interesting, I have solved the “-Wno-long-double” problem and now I am back together with everyone else at the _jpeg_resync_to_restart error!

    I also tried the otool trick, but it shows no dependency at all on libjpeg! During PIL compilation, the output correctly says that Jpeg support is present.


    October 29, 2009 at 5:14 pm

  27. Remi: if you are still reading this, I am trying following your instructions because they are slightly different than everything I have tried so far, but I’ve bumped in an error already when making jpeg-7. The output I get is . Did you have this, too? It does not really look like I can do a make install after this!


    October 30, 2009 at 6:31 am

  28. I’m stuck with the same issue being described by most others immediately above me.

    Has anyone found a solution? (I will post if I figure it out…)


    October 30, 2009 at 7:10 am

  29. I solved this issue (for me, anyway) today.

    - Make sure that you are NOT using GCC 4.0. That means those export lines in your .bash_profile file that you needed to get MySQLdb working now need to go away.
    - I used libjpeg 7 (, even though I doubt it was necessary.
    - Before installing PIL but after installing libjpeg, I changed the “JPEG_ROOT = None” line in my file to “JPEG_ROOT = libinclude(“/usr/local”)”


    October 30, 2009 at 7:44 am

  30. I’ve heard there are some wildlife groups trying to get Apple to do more stuff with the actual S.L.’s lol. I don’t know- people are saying it’s good PR for Apple- they should jump on that.


    November 4, 2009 at 6:19 am

  31. building libjpeg, and then using pip to install pil worked, but I had to tweak the command a bit:

    $ cp /usr/share/libtool/config/config.sub .
    $ cp /usr/share/libtool/config/config.guess .
    $ CC=”gcc -arch i386″ ./configure –enable-shared –enable-static
    $ make
    $ sudo make install

    $ sudo pip install pil


    July 1, 2010 at 3:24 am

  32. Thanks for jotting this down! One thing to note that PIL must be installed *after* installing libjpeg. I had an existing installation of PIL that I had to reinstall before it picked up the libjpeg libraries.


    September 2, 2010 at 4:38 am

Comments are closed.