132

I've just updated my Mac OS to 10.9 and I discovered that some (all?) of my Python modules are not here anymore, especially the Image one.

So I try to execute sudo pip install pil, but I get this error:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found

#      include <X11/Xlib.h>

               ^

1 error generated.

error: command 'cc' failed with exit status 1

My Xcode is up-to-date and I don't have any idea. Is it possible that PIL is not yet 10.9 compatible ?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Vincent Audebert
  • 1,846
  • 2
  • 15
  • 28

28 Answers28

211

Following worked for me:

ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11
sudo pip install pil

UPDATE:

But there is more correct solution below, provided by Will.

open your terminal and execute: xcode-select --install

Dmitry Demidenko
  • 3,427
  • 1
  • 22
  • 22
  • 2
    Your answer has a typo, it's `MacOS10.9.sdk` not `MacOS0.9.sdk`. – Bryan Veloso Oct 24 '13 at 08:17
  • 3
    If you also want to have a PIL/Pillow with zlib/png/zip support you also need to do: `ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/zlib.h /usr/local/include/` – gromgull Nov 11 '13 at 09:33
  • If it does not work, try slightly different directories: `sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/X11 ` and then `sudo pip install Pillow` – Sergey Orshanskiy Dec 01 '13 at 02:03
  • instead of making symlinks installing the command line tools (as suggested in another answer) fixes the solution properly. – Jehiah Dec 07 '13 at 18:34
  • 26
    the suggested command brings up an error dialog from Apple. First it asks whether I want to Get XCode (which I have) or "Install". I choose install. It pops up a EULA, I accept, then an error dialog comes up: "Can't install the software because it is not currently available from the Software Update server." – Matt Feifarek Dec 11 '13 at 09:16
  • @MattFeifarek: Try looking at [this thread](http://stackoverflow.com/questions/19907576/xcode-is-not-currently-available-from-the-software-update-server) – Casebash Jan 08 '14 at 06:24
  • The "More Correct Solution" did not work for me (in fact the command line tools were already installed in the normal way, so I got the same error as in @MattFeifarek's comment). But the symlink did fix the problem (allowing X11/Xlib.h to be found). So I think the second solution is only a more correct solution _if it works_! For the rest of us, the symlink is the better solution. – Matt Feb 23 '14 at 09:35
  • 7
    I encountered an error `Downloading/unpacking pil Could not find any downloads that satisfy the requirement pil Some externally hosted files were ignored (use --allow-external pil to allow). Cleaning up... No distributions at all found for pil Storing debug log for failure in /Users/Usermania/.pip/pip.log` – Leonid Mar 26 '14 at 03:26
  • 1
    ln: /usr/local/include/X11: No such file or directory I have no /usr/local/include/X11 direcotry? – pigletfly Mar 29 '14 at 05:22
  • Works also for Yosemite OSX 10.10 – Raffi Oct 31 '14 at 13:59
  • Don't mess around with symlinks, run `xcode-select --install` and you're fine. (as Will mentioned) – tamasgal Nov 05 '14 at 15:28
  • USE THE UPDATE METHOD: xcode-select --install WORKS! – Paul Kenjora Feb 11 '15 at 22:47
  • Although `xcode-select --install`is helpful, I still had to symlink X11 issuing `ln -s /opt/X11/include/X11 /usr/local/include/X11` - JFYI, I was trying to build [Dlib](http://dlib.net) using the included Cmake file (examples), on El Captian (OSX 10.11.1). – Big Rich Nov 13 '15 at 11:46
  • `ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11` worked on MacOS Mojave 10.14 – Most Wanted Apr 30 '19 at 13:25
102

open your terminal and execute:

xcode-select --install

Willem
  • 1,304
  • 1
  • 8
  • 7
  • 3
    The question is not about installing Xcode but PIL... Moreover, I explained that I already had Xcode installed and up-to-date. – Vincent Audebert Nov 06 '13 at 20:08
  • 5
    This solves the problem as well (it install the command line tools that are not installed by default with Xcode). – Rob Osborne Nov 18 '13 at 22:48
  • 1
    This is all I needed to do, none of that symlinking stuff. – joerick Nov 26 '13 at 09:59
  • 1
    @VincentShowcaseWorkshop Xcode does not install the command line tools by default. I had to do this to get past the same problem as the OP's even though I most definitely already had Xcode installed and up to date on Mac OS 10.9.2. – Tony Adams Apr 29 '14 at 16:54
  • This fixes the issue with Mac version 10.11.2 (15C50). – webtweakers Jan 20 '16 at 14:26
34
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11/ /usr/local/include/X11

helps for me! os x 10.9

pip install pillow

but! after pip install ...

*** ZLIB (PNG/ZIP) support not available

and finally i fix it by running:

xcode-select --install

then reinstall pillow

pip install pillow

PIL SETUP SUMMARY
    --------------------------------------------------------------------
    version      Pillow 2.2.1
    platform     darwin 2.7.5 (default, Aug 25 2013, 00:04:04)
                 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
    --------------------------------------------------------------------
    --- TKINTER support available
    --- JPEG support available
    --- ZLIB (PNG/ZIP) support available
    --- TIFF G3/G4 (experimental) support available
    --- FREETYPE2 support available
    --- LITTLECMS support available
    --- WEBP support available
    --- WEBPMUX support available
    --------------------------------------------------------------------
Cocoatype
  • 2,572
  • 25
  • 42
klem4
  • 367
  • 2
  • 6
  • updated to mavericks yesterday and just today I was starting a project, you just saved me hours of heartache THANKS! – javiercf Oct 24 '13 at 03:01
  • This I had to do $> ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pillow – Sudhir Mar 26 '14 at 06:08
  • 1
    thanks! for 10.10 use: sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11 – rozochkin Feb 18 '15 at 12:10
14

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()
x86
  • 211
  • 3
  • 2
11

Here is what I did, some steps may not be necessary just for PIL but I needed libpng and others anyways:

1) Run xcode install, use this command or download updates from the app store:

xcode-select --install

1b) Add the Command Line Tools optional tool, in Mountain Lion this was an option on the xcode Download page, but now you have to register with your apple id and download from: https://developer.apple.com/downloads/

Look for Command Line Tools (OS X Mavericks) for Xcode

2) Install everything needed for python (using brew), I believe you can use port as well:

brew install readline sqlite gdbm
brew install python --universal --framework 
brew install libpng jpeg freetype

Unlink/ relink if needed i.e. if upgrading.

3) Install Pip and required modules:

easy_install pip 
sudo pip install setuptools --no-use-wheel --upgrade

4) Finally this works with no errors:

sudo pip install Pillow

UPDATE 11/04/14: PIL repo no longer receives updates or support so Pillow should be used. The below is now deprecated so stick with Pillow.

sudo pip install pil --allow-external pil --allow-unverified pil

UPDATE (OLD) : The same thing applies when installing Pillow (PIL fork) and should be mentioned as its quickly becoming a replacement in most cases of PIL. Instead of installing pip in step 4, run this instead:

sudo pip install Pillow

Hope this helps someone!

radtek
  • 34,210
  • 11
  • 144
  • 111
  • Step 4) may end with sth like `_imagingft.c:73:10: fatal error: 'freetype/fterrors.h' file not found`. But could be resolved following http://stackoverflow.com/questions/20325473/error-installing-python-image-library-using-pip-on-mac-os-x-10-9. – Bugs Bunny Nov 04 '14 at 15:06
  • are you installing pil or pillow? PIL is deprecated, I'll update this. – radtek Nov 04 '14 at 16:26
  • Doesn't matter. PIL or Pillow, it might still be useful for some poeple to resolve symlinking freetype/freetype2 issue. But thanks! – Bugs Bunny Nov 04 '14 at 17:11
  • Yeah I added stuff in step 2 for unlink /link if upgrading. If missing something can you edit and I'll accept? – radtek Nov 04 '14 at 17:17
  • 1
    sudo pip install pil --allow-external pil --allow-unverified pil helped me in 2015 – fun_vit Feb 10 '15 at 14:11
9

installing command line tools fixed the issue for me

you have to install them separately as they are not part of the packages in xcode now:

https://developer.apple.com/downloads/index.action?=command%20line%20tools#

Formulka
  • 91
  • 1
  • 1
    I definitely prefer this approach. I hate doing custom symlinking with system packages... you never know what is going to break on the next update... – tatlar Nov 13 '13 at 18:03
  • That appears to be a bad URL now. – Matt Feifarek Dec 11 '13 at 09:14
  • @MattFeifarek that URL worked for me today. I had to log in with a dev account, but it then took me to the relevant command line tools download page. – Tony Adams Apr 29 '14 at 16:56
8

Non of those worked for me.. I kept receiving:

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit status 1

So I found a work around with the following solution:

sudo export CFLAGS=-Qunused-arguments
sudo export CPPFLAGS=-Qunused-arguments
sudo pip install PIL --allow-external PIL --allow-unverified PIL

This way I was able to install.

tonhozi
  • 440
  • 5
  • 6
  • This is the one that fixed it for me. If you are running a virtual enviroment, you do not need the sudo command. – Eric May 20 '14 at 18:17
  • Thank you! This works running a Python virtual environment. I didn't have Xcode currently installed so this saved me the download time. – Jamie Counsell Jul 21 '14 at 16:18
  • This works great for old xcode in 10.8, did it work for Mavericks? – radtek Sep 04 '14 at 14:45
6

I had a similar problem: Installing pillow failed with clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future], installing command line tools failed with Can't install the software because it is not currently available from the Software Update server., and even after installing the command line tools manually, the compilation of PIL failed.

This happens cause clang under the newest version of xcode doesn't warn on unknown compiler flags, but rather stop the compilation with a hard error.

To fix this, just run export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future" on the terminal before trying to compile (installing pil).

nicolaslara
  • 151
  • 2
  • 1
5

Simply run

pip install pil --allow-external pil --allow-unverified pil

jqualls
  • 1,483
  • 14
  • 19
3

This my steps on mac os 10.9.1

1. sudo su
2. easy_install pip
3. xcode-select --install
4. pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL
saranpol
  • 2,177
  • 1
  • 23
  • 22
2

You could use Homebrew to do the install http://brew.sh

brew tap Homebrew/python
brew install pillow
rchapman
  • 91
  • 2
  • Hello rchapman. When I run `brew` to install samueljohn/python/pillow, it gives a warning like: `pillow-2.5.1 already installed, it's just not linked`. And before this, there are 15 warnings like: `Could not tap homebrew/python/cpyrit-cuda over samueljohn/python/cpyrit-cuda`. Any ideas why this happens? Or how can I link pillow? – 0xmtn Jul 21 '14 at 03:45
2

Make sure you have Command Line Tools installed on your xcode. Then execute:

sudo pip install pil --allow-external pil --allow-unverified pil
a14m
  • 7,808
  • 8
  • 50
  • 67
2

I was having the following error

building 'PIL._imagingft' extension
_imagingft.c:62:10: fatal error: 'freetype/fterrors.h' file not found

#include <freetype/fterrors.h>

         ^

1 error generated.

error: command 'cc' failed with exit status 1

The solution to this was to symlink freetype2 to freetype and this solved the problem.

Geoffrey
  • 141
  • 2
  • 3
2

I didn't want to install XCode (I don't use it) and I'm loath to fiddle with Application directory. I've cribbed from the many answers in this post and the following two steps work for me with 10.9.5:

sudo easy_install pip
sudo pip install pillow

It did appear to me strange that I had to use easy_install to install pip. But pip didn't want to work for me before that (re-)install.

CyberFonic
  • 3,957
  • 1
  • 21
  • 21
1

Found the solution ... You've to symlink X11 like this ln -s /opt/X11/include/X11 /usr/local/include/X11 and then sudo pip install pil should work.

Vincent Audebert
  • 1,846
  • 2
  • 15
  • 28
  • not working for me... did you update your xcode before making it to work? did you restart your mac lots of times? this is frustrating me. ughs. – bonbon.langes Oct 23 '13 at 14:48
  • I did my xcode update before and I restarted my mac even if I'm not sure it's helpful. Maybe the path to your X11 is not the same for you. Try some of the other answers maybe. – Vincent Audebert Oct 23 '13 at 20:26
1

Reusing @DmitryDemidenko's answer that is how it worked for me:

ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11

and then

sudo pip install -U PIL --allow-external PIL --allow-unverified PIL
1

Execute the bellow command lines. Works like a charm on Mac OS 10.9.5

easy_install pip

sudo pip install setuptools --no-use-wheel --upgrade

sudo pip install Pillow

Best, Theo

0

That's what I did:

First upgrade to Xcode 5 (I am running 10.9). Then, execute the following commands in a terminal:

$ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
$ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 usr/include/
Soravux
  • 9,653
  • 2
  • 27
  • 25
  • 1
    A similar answer was given and accepted two weeks ago. I fail to see the additional value of yours... – Soravux Nov 06 '13 at 05:04
  • Well, this answer has different paths than the accepted one. I added this version as a comment to the accepted answer. The command is `sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/X11` – Sergey Orshanskiy Dec 01 '13 at 02:04
0

A more complete solution requires the installation of the Xquartz X11 subsystem that has been built outside of Apple for several years now. Here are the steps I used to get it all working

  1. Install XQuartz from http://xquartz.macosforge.org/landing/
  2. Run sudo pip install pillow
Sammy Spets
  • 261
  • 2
  • 2
0

As the accepted answer is the right one with xcode-select --install but some people (including me) may encounter Can't install the software because it is not currently available from the Software Update server If you are using beta software (as I am using Yosemite now and had the same problem) you NEED to get the CLT separately since it is NOT included in XCode (even xcode beta) Head over to developers.apple.com and get CLT tools for your OS ;)

P.S. You don't need XQuartz for PIL or Pillow to work

Mohibeyki
  • 459
  • 6
  • 16
0

My machine which was recently upgraded from OS 10.8 -> 10.9 got stuck in a loop between xcrun and lipo.

Rename /usr/bin/lipo to /usr/bin/lipo_broken

Refer to this thread for further information on how to resolve:

xcrun/lipo freezes with OS X Mavericks and XCode 4.x

Community
  • 1
  • 1
0

Install Pillow instead:

sudo pip install pillow
famousgarkin
  • 13,687
  • 5
  • 58
  • 74
Bobo
  • 8,777
  • 18
  • 66
  • 85
  • You still need all the pre-config as you would for PIL – radtek Sep 04 '14 at 14:43
  • @radtek no you don't on mac 10.9. Have you actually tried the command before you down-voted my answer? – Bobo Sep 23 '14 at 16:12
  • I didn't downvote ur answer, i upvoted, but yeah I did try. I actually did this a few times now and I didn't need step 1b actually but everything else I needed. – radtek Sep 23 '14 at 17:13
0
ln -s /usr/local/include/freetype2 /usr/local/include/freetype
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pil
softvar
  • 17,917
  • 12
  • 55
  • 76
0

Try this:

ln -s /usr/local/include/freetype2 /usr/local/include/freetype
0
sudo pip uninstall pillow
pip install pillow

worked for me. I'm running Python 2.7.9 on Yosemite.import PIL now works for me.

kilojoules
  • 9,768
  • 18
  • 77
  • 149
0

Installing PIL (Imaging.1.1.7) on Mac OSC 10.10 Yosemite. I tried numerous fixes recommended here but ran into trouble with each one. I finally solved this problem by editing the setup.py file such that:

TCL_ROOT = "/opt/X11/include"

which passes the appropriate include path for X11 in the compilation of _imagingtk.c, which was causing the problem for me. Worked immediately after change.

0

I've moved from pyenv to virtualenv and this fixed my problem.

ipeacocks
  • 2,187
  • 3
  • 32
  • 47
-4
  1. ln -s /opt/X11/include/X11 /usr/local/include/X11
  2. pip install pil without sudo
Sergey
  • 425
  • 1
  • 4
  • 11