Mac OS X Lion: Install the Python Image Library (PIL)

First make sure you have lib jpeg install for JPEG handling

1
2
3
4
5
6
$ curl -O http://www.ijg.org/files/jpegsrc.v8c.tar.gz
$ tar zxvf jpegsrc.v8c.tar.gz
$ cd jpeg-8c/
$ ./configure
$ make
$ sudo make install

Then I use pip to install PIL

1
$ sudo pip install PIL

(Make sure you have Xcode installed on your machine or you may run into C compiler errors)

 

  • Erick Yellott

    Simple as copy pasta. Thanks. 

  • Monti

    it says me ‘pip:command not found’ :S

    • Anonymous

      Make sure you install PIP first. You must install form source using this package: http://pypi.python.org/pypi/pip

  • Anonymous

    Hi Monti,

    You will need to install PIP on your machine if it’s not there already. I have it installed on all my machine so I take it for granted!

    If you’re linux (ubuntu), type in command line:

    apt-get install pip

    If you’re on Mac, you would have to install from source. You can download the package here: http://pypi.python.org/pypi/pip#downloads

    Then follow the install instructions in the attached install guide.

  • Guest

    Every other site that tried to explain the process was too cryptic, had an insane amount of commands and never worked. This took less than 10 minutes, even w/ the pip installation I had to do, and ran smoothly first try. I wish all explanations were as strait forward as this. Thanks!

  • Anonymous

    Simplicity is the last step of art. Brilliant how-to.

  • Lauri Takacsi-Nagy

    Thank you so much. I spent 3 days trying to do all this ridiculous stupid stuff and then just followed the instructions here. And it worked.

  • Thom Allen

    You are a savior. This usually takes me FOREVER. I used easy install instead of pip, worked fine. Thanks!

  • Vincent

    Hi ! Tried to follow instructions, but an error occurs at line 4 (./configure)
    Here is the message on the terminal:
    checking build system type… i386-apple-darwin12.0.0checking host system type… i386-apple-darwin12.0.0checking target system type… i386-apple-darwin12.0.0checking for a BSD-compatible install… /usr/bin/install -cchecking whether build environment is sane… yeschecking for a thread-safe mkdir -p… ./install-sh -c -dchecking for gawk… nochecking for mawk… nochecking for nawk… nochecking for awk… awkchecking whether make sets $(MAKE)… nochecking for style of include used by make… nonechecking for gcc… nochecking for cc… nochecking for cl.exe… noconfigure: error: in `/Users/mezigue/jpeg-8c’:configure: error: no acceptable C compiler found in $PATH

    It seemed strange: I have Xcode installed and  gcc-42-5666.3-darwin11 too

    Thanks for any help.
    I work on Moutain Lion
    (vous pouvez me répondre en français^^)

  • Vincent

    Ooops, I answer to myself: after upgrading Xcode I omit to resintall devtools
    Now procedure works fine.
    And PIL is here !
    Thanks Guillaume !

  • Vincent

    Hello, I have a problem with this installation: it works fine with the admin account, but with an account no admin, PIL is not found by Python? Is there any way to fix this ?
    PS: I’m not a guru of the terminal, and I need PIL on no admin account for education purposes (a new option in french baccalaureat). 
    Thanks for any help !

    • Anonymous

      Hi Vincent, what do you mean by admin account? Have you got access as root into a terminal?
      You may need root access to install PIL, though once it’s installed it should be there for all users. Unless, your account is running a different version of Python so it doesn’t have the same packages. 

      • Vincent

        Well, I have two users account on the mac:
        - teacher’s account (can administrate)
        - student’s account (non admin, parental controls)

        After your answer I have discover the origin of my problem.

        When I use IDLE (on both accounts) PIL is found.
        When I use CodeRunner (a light code editor) PIL is found on the first account (admin) but not on the second one. I think the problem is in the “Run command” on this software (which launch python 2.7.2 instead of 2.7.3).

        So, do you know what is the command (in terminal) to “force” python 2.7.3 to be the default version ?

        Thanks for any help
        (and sorry for my poor english)

        • Anonymous

          You can’t really force the system to use a specific version of Python, but you can make sure that the default Python eg on Linux: /user/bin/python point to the right version of python. Also I would recommend uninstalling the version that you don’t want to avoid confusion.

          Alternatively, you can install PIL on each version by calling the install script with the python version, eg: python2.7.2 setup.py install

          Still you’ll be better of with one version only!

          • Vincent

            I finally fix my problem: in the mac distribution of Python, there is a folder called Python 2.7 (in the application folder). In this folder, there is a shell script. I run this script and miracle ! the default python is now 2.7.3.
            Something remains strange for my poor mind: I only have to do this on the student’s account. On the teacher’s account, the version is naturally 2.7.3

            Bref, je comprends pas tout (mais je me soigne) !

            Thanks Guillaume

  • http://www.facebook.com/theamishone Powers Kenny

    Thanks, Extremely helpful. All other advice I found on this was very out of date.

  • http://twitter.com/mHossameldin Mahmoud Hossam

    Thank you very much man, really helpful :)

  • Anon

    Thanks for the info!!!

  • Don Cross

    Thank you, Guillaume! These instructions saved me a lot of time and headaches!

  • sandeep

    A bit embarrassing, but I got the following errors, can someone point out what is wrong
    On sudo pip install PIL I get
    Downloading/unpacking PIL
    Could not find any downloads that satisfy the requirement PIL
    No distributions at all found for PIL
    ——————
    and using easy_install gives a big error of which last line is

    ile “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/package_index.py”, line 475, in fetch_distribution

    AttributeError: ‘NoneType’ object has no attribute ‘clone’

    • guillaumepiot

      PIL website (http://www.pythonware.com/products/pil/) seems to be down, so that may be the issue, no package downloads are available at the moment. It’ll be worth waiting for a bit I guess.

  • Mathieu

    Hello guys,

    This seems super simple but something is still wrong on my machine.

    I had PIL installed without jpeg support and I want to add support. I installed the jpeg library as described. Then using pip, uninstalled and reinstalled pil.

    At the end of the PIL setup, I get the following print in the console that looks promising
    ——————————————————————–
    PIL 1.1.7 SETUP SUMMARY
    ——————————————————————–
    version 1.1.7
    platform darwin 2.7.1 (r271:86832, Aug 5 2011, 03:30:24)
    [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]
    ——————————————————————–
    — TKINTER support available
    — JPEG support available
    — ZLIB (PNG/ZIP) support available
    — FREETYPE2 support available
    *** LITTLECMS support not available
    ——————————————————————–

    Unfortunately, if I start ipython and type
    > import Image
    > im = Image.open(“test.jog”)
    > im.show()
    I get
    IOError: decoder jpeg not available

    I made sure that I’m using the same python install everywhere. If I uninstall PIL using PIP, then “import Image” fails.

    If you have any advise, let me know.
    Thanks
    Mathieu