I've tried googling & looking up some other people's questions. However, I still couldn't find a clear/simple recipe to install PIL (for python 2.6 or 2.7) on mac os x 10.7.2 Lion.
-
The accepted answer does not work in my OS X El Capitan 10.11.4. I opened a new thread about this here http://apple.stackexchange.com/q/233405/15504 – Léo Léopold Hertz 준영 Apr 01 '16 at 21:03
9 Answers
If you use homebrew, you can install the PIL with just brew install pil
. You may then need to add the install directory ($(brew --prefix)/lib/python2.7/site-packages
) to your PYTHONPATH, or add the location of PIL directory itself in a file called PIL.pth
file in any of your site-packages directories, with the contents:
/usr/local/lib/python2.7/site-packages/PIL
(assuming brew --prefix
is /usr/local
).
Alternatively, you can just download/build/install it from source:
# download
curl -O -L http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
# extract
tar -xzf Imaging-1.1.7.tar.gz
cd Imaging-1.1.7
# build and install
python setup.py build
sudo python setup.py install
# or install it for just you without requiring admin permissions:
# python setup.py install --user
I ran the above just now (on OSX 10.7.2, with XCode 4.2.1 and System Python 2.7.1) and it built just fine, though there is a possibility that something in my environment is non-default.

- 5,405
- 8
- 44
- 82

- 37,545
- 9
- 92
- 87
-
when i run python steup.py build i get "unable to execute /usr/bin/gcc-4.2: No such file or directory".. im on OSX 10.7.3 and xcode 4.2 – AlBeebe May 02 '12 at 06:39
-
7For those having trouble with gcc or llvm-gcc command not found error when running setup.py, check in xcode that commande line tools are installed by going to "Xcode -> Préférences -> Downloads -> Commande Line Tools -> Install". – Ben G Jun 13 '12 at 17:05
-
also, you should go look at my solution and make sure to install freetype and libjpeg, or your PIL install will be lacking crucial dependencies for some of the components of PIL. – Francis Yaconiello Jul 08 '12 at 21:06
-
2Thanks, I updated the URL. This is pretty old, and nowadays I would actually just recommend `pip install pillow` instead. Which probably benefits from first calling `brew install freetype libpng libjpeg`. – minrk Jul 03 '13 at 05:11
-
2how should I add this to PYTHONPATH? Just paste in .bash_profile? For now it looks like (only entries concerning python): #export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH export PATH=/usr/local/share/python:$PATH – andilabs Aug 07 '13 at 13:07
-
Update: nowadays you should use `brew install pillow` instead. `brew install pil` no longer works. – Mathias Bynens May 25 '14 at 11:08
-
This is something I wrote for the folks at work. It's a full workup for getting a clean OSX Lion working virtualenv using django + git + some other stuff:
https://gist.github.com/1781374
The most important lines for you are:
Install libjpeg (PIL req)
curl -O http://www.ijg.org/files/jpegsrc.v8c.tar.gz
tar -xvzf jpegsrc.v8c.tar.gz
cd jpeg-8c
./configure
make
sudo make install
cd ../
Install freetype (more PIL requirements)
curl -O http://ftp.igh.cnrs.fr/pub/nongnu/freetype/freetype-2.4.5.tar.gz
tar -xvzf freetype-2.4.5.tar.gz
cd freetype-2.4.5
./configure
make
sudo make install
cd ../
Install PIL (usually in the requirements.txt so I don't have it in the above linked instruction)
pip install PIL
or some folks have to (not sure what the configuration difference that causes this is):
sudo pip install PIL
EDIT:
ALSO note that with LION command line tools aren't installed by default, you have to manually enable them, open XCode got to preferences then downloads and select command line tools to be installed before you can compile anything (noted at the top of my GIST)

- 24,647
- 4
- 70
- 96

- 10,829
- 2
- 35
- 54
-
2If you are on OSX and using [homebrew](http://mxcl.github.io/homebrew/) you can just do `brew install freetype libjpeg`. – Nathan Villaescusa Jun 18 '13 at 01:04
-
Also note: As of Django 1.6 usage of PIL is going to be dropped in favor of Pillow, https://code.djangoproject.com/ticket/19934 – Francis Yaconiello Aug 16 '13 at 13:49
-
2For OSX 10.9.2 I was only able to install it by typign `sudo pip install pillow` – nkha Feb 26 '14 at 09:58
One way is via Macports
Install the base macports as per the installation guide
Then install the py27-pil port by port install py27-pil
You will then need to use the python installed by macports by using port select --set python python27
I find it easier to use a package manager like macports (or fink or homebrew) when you require C libraries to be installed as well as python code.

- 32,227
- 27
- 88
- 117
-
Thanks! I was trying port select --set python 27 and that didn't work so I was confused :P – Thor Correia Jul 06 '12 at 19:05
Works for me ( OS X Yosemite 10.10.2 - Python 2.7.9 ) :
xcode-select --install
sudo pip install pillow
Try this to check it:
from PIL import Image
image = Image.open("file.jpg")
image.show()
http://rudix.org provides hassle free installation for lots of precompiled unix packages including pil and pillow. After I tried every single answer on StackOverflow, the only thing that ended up working was this (I wish I had found them before I tried everything else). http://rudix.org/packages/pil.html and http://rudix.org/packages/pillow.html

- 161
- 1
- 2
-
Tried everything else, several times. This just worked for me! Many many thanks. – PhoebeB Nov 20 '13 at 18:35
-
Great job posting this the I tried everything as well before reading this post. Worked for me. OSX Mavericks. – MacUser Jul 14 '14 at 01:46
On Mac OS X, if you prefer to install PIL using pip inside a virtualenv, then you might have to make PIL use Mac's builtin freetypes by running:
$ ln -s /usr/X11/include/freetype2 /usr/local/include/
$ ln -s /usr/X11/include/ft2build.h /usr/local/include/
$ ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/
$ ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/libfreetype.dylib
$ pip install PIL

- 380
- 2
- 10
Install the Python Imaging Library:
sudo pip install pillow

- 5,185
- 3
- 27
- 36
-
This is the right answer here for newer systems than Lion! PIL has been depreciated since 2010 https://mail.python.org/pipermail/image-sig/2010-August/006480.html – Léo Léopold Hertz 준영 Jun 07 '16 at 16:22
I was trying to execute a Python script with administrative privileges in a Mac (running on Lion) and looking at this post I found out that all I needed to do was launch Python with Administrative privileges by using the "sudo" command in the Terminal.
Like that: "sudo Python" and then executing the script.
I know it is pretty basic but it was exactly what I needed to get my script working...

- 11
- 1