26

I have a fresh install (started with a wiped drive) of Snow Leopard with the developer tools installed during the Snow Leopard installation.

I then installed Python 2.6.2, replacing the Snow Leopard default python 2.6.1. I've tried to install PIL by:

  1. easy_install
  2. pip
  3. downloading source and running python setup.py build manually.

All yield the same error (link to pip log: http://drop.io/gi2bgw6). I've seen others have had success installing PIL using the Snow Leopard default python 2.6.1, so I'm not sure why I'm having so much trouble getting it to work with 2.6.2.

Mike Lawrence
  • 1,641
  • 5
  • 20
  • 40
  • easy_install and pip are doing the same things behind scenes just like installing manually from the source. – viam0Zah Apr 27 '10 at 16:14

12 Answers12

18

The problem I ran into was that PIL was being compiled against PowerPC architecture (-arch ppc).

Do this before setup/build/compile:

export ARCHFLAGS="-arch i386"

(Assuming you're on i386)

Kyle Fox
  • 3,133
  • 4
  • 23
  • 26
  • 2
    I have successfully installed PIL on Snow Leopard 64 bit by using your suggestion, but changing the arch to x86_64, then using easy_install to install PIL. (export ARCHFLAGS="-arch x86_64") – Pascal Bourque May 25 '11 at 15:05
12

The python.org Python was built with an earlier gcc. Try using gcc-4.0 instead of SL's default of 4.2:

export CC=/usr/bin/gcc-4.0

See similar problem here.

That gets past the stdarg problem. You may then run into later build problems with various dependent libraries.

BTW, gcc-4.0 and gcc-4.2 are both included with Snow Leopard's Xcode 3 so no additional installs are needed.

UPDATED 2011-05: Note, that the newer Xcode 4, released for experimental use with 10.6 and expected to be standard with 10.7, no longer includes PPC support so, if you install Xcode 4, this suggestion will not work. Options include using the newer 64-bit/32-bin Python 2.7.x installers from python.org or installing a newer Python 2.6 and PIL and the various 3rd-party libs using MacPorts, Homebrew, or Fink.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • Works perfectly! I did have trouble at first insofar as "import _imaging" would fail, but I tracked that down to a problem with libjpeg so I re-built libjpeg using gcc-4.0, re-installed PIL, and it's all working like a charm now. Thanks! – Mike Lawrence Sep 18 '09 at 01:54
  • 1
    Unfortunately, xcode 4.0 appears to no longer include gcc-4.0, so this solution no longer works if you start with a fresh install of the os and install only xcode 4.0. I guess I could install xcode 3, then reinstall xcode4, but that seems like a pain. – Mike Lawrence Mar 17 '11 at 14:34
  • Starting with the Python 2.7.1 and 3.2 releases, there are now two python.org installers for each release. The newer variant is a 64-bit/32-bit build for Mac OS X 10.6 and above and uses gcc-4.2. The other installer is the traditional 32-bit-only (Intel/PPC) build for OS X 10.3 and above and requires gcc-4.0. So options include: install gcc-4.0 and the 10.4u SDK from Xcode 3 or use the new installer variant or install Python/PIL/libjpeg et al using MacPorts or Homebrew or Fink. – Ned Deily Mar 17 '11 at 16:44
  • 1
    I had the same problem recently and unfortunately this solution didnt work for me. I succeeded in fixing the problem though, but I did was to use macports and doing the following: **port install py26-pil +universal** after which i located the PIL installation and copied it into my site-packages folder and voila! 2 nights of heartache was solved. my PC spec is Mac OS X 10.6.7 Intel Core 2 Duo. However please note that you'll need to have libjpeg properly installed if it currently isn't. Simply use **port install jpeg +univseral** – Emotu Balogun Apr 21 '11 at 16:35
  • 1
    Nothing else was working for me, so I had to resort to macports :-( Stupid Apple, how could they not include the libraries in Xcode4. Oh well. – Luke May 21 '11 at 01:59
  • 1
    No doubt Apple is sending a signal to developers that they plan to no longer support PPC archs in OS X 10.7 and they've released Xcode 4 to allow everyone to experiment and work out the issues before Lion is officially released. I've updated the reply a bit to take that into account. – Ned Deily May 21 '11 at 03:30
7

Modified Answer

Here are the steps that I took to successfully install PIL on Mac OS X 10.6 (without using MacPorts or Fink).

  1. Install readline

    cd ~/src
    curl -O ftp://ftp.cwru.edu/pub/bash/readline-6.0.tar.gz
    tar -xvzf readline-6.0.tar.gz
    cd readline-6.0
    ./configure  
    make  
    sudo make install
    
  2. Install gbdm

    cd ~/src
    curl -O ftp://mirror.anl.gov/pub/gnu/gdbm/gdbm-1.8.3.tar.gz
    tar -xvzf gbdm-1.8.3.tar.gz
    cd gdbm-1.8.3
    # Need to modify Makefile.in
    perl -pi -e 's/BINOWN = bin/BINOWN = root/' Makefile.in
    perl -pi -e 's/BINGRP = bin/BINGRP = wheel/' Makefile.in
    ./configure
    make
    sudo make install
    
  3. Compile the latest Python 2.6.2+ from the Mercurial Repo

    cd ~/development
    hg clone http://code.python.org/hg/branches/release2.6-maint/ python-release2.6-maint.hg
    cd python-release2.6-main.hg
    ./configure --enable-framework MACOSX_DEPLOYMENT_TARGET=10.6
    make
    sudo make frameworkinstall
    

    Note: I did receive the following errors after running make. However, I continued on as I wasn't worried about missing these modules, and I was able to successfully install PIL.

    Failed to find the necessary bits to build these modules:
    _bsddb             dl                 imageop         
    linuxaudiodev      ossaudiodev        spwd            
    sunaudiodev                                           
    To find the necessary bits, look in setup.py in detect_modules() for the module's name.
    
    
    Failed to build these modules:
    Nav                                                   
    
    running build_scripts
    
  4. Update .bash_profile for the new Python 2.6.2+ and for virtualenvwrapper

    # Set PATH for MacPython 2.6 if Python2.6 is installed
    if [ -x /Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 ]; then
        PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"
        export PATH
    fi
    
    # MDR April 23, 2009: Added for virtualenvwrapper
    if [ -x   /Library/Frameworks/Python.framework/Versions/2.6/bin/virtualenvwrapper_bashrc ]; then
        export WORKON_HOME=$HOME/.virtualenvs
        export PIP_VIRTUALENV_BASE=$WORKON_HOME
        source /Library/Frameworks/Python.framework/Versions/2.6/bin/virtualenvwrapper_bashrc
    fi
    
  5. Install easy_install, pip, virtualenv, and virtualenvwrapper for Python 2.6.2+

    curl -O http://peak.telecommunity.com/dist/ez_setup.py
    sudo python ez_setup.py
    sudo easy_install pip
    sudo easy_install virtualenv
    sudo easy_install virtualenvwrapper
    
  6. Create a virtualenv and then use pip to install PIL

    mkvirtualenv pil-test
    cdvirtualenv
    easy_install pip
    pip install http://effbot.org/downloads/Imaging-1.1.6.tar.gz
    

Note: I was not able to install PIL using pip install pil, so I installed from the URL as shown above.

Original Answer

From what I can see in your pip-log.txt file it appears that you installed Python 2.6.2 using the Mac Installer Disk Image from Python.org released on April 16, 2009. Can you confirm this?

From the pip log, gcc failed with exit status 1. The offending gcc command from your pip log is as follows:

gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -DHAVE_LIBJPEG -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/local/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _imaging.c -o build/temp.macosx-10.3-fat-2.6/_imaging.o

This appears to be a problem related to Snow Leopard changing the default value for the -arch flag from i386 to x86-64 according to Ronald Oussoren in Message 92083 of Python Issue 6802. There is a patch available Python 2.6.2, but it has not been integrated into the Mac Installer Disk Image.

Your best solution that doesn't involve MacPorts or Fink would probably be to compile and install Python from the 2.6 release branch from either the Mercurial Python Repository or the Subversion Python Repository. According to Message 92315 of Issue 6802, Ronald Oussoren fixed this in Revision r74686.

I've been seeing similar errors using Python 2.6.2 installed from the Mac Disk Image while trying to then install Fabric in a virtualenv, so I plan to compile and install from the 2.6 release maintenance branch. If you want, I'll update when successful.

Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163
  • Issue6802 has to do with building Python itself, not building Python extensions with distutils. The workaround of using gcc-4.0 should take care of the problem here. – Ned Deily Sep 17 '09 at 16:51
  • You certainly could build everything from scratch like that but, if you're going to go down that route, why not let MacPorts do all the heavy lifting for you? Step 1 - If necessary, download and install the MacPorts base for 10.6. Step 2. "sudo port install py26-pil" which should pull in all the necessary dependencies. Step 3. Wait a bit until it's done and then you're done. – Ned Deily Sep 18 '09 at 00:40
  • I have no experience with MacPorts, so my desire to not use it is simply 1) personal preference to be a minimalist where it makes sense and 2) I feel like I've seen one too many negative blog posts about MacPorts. Jesse Noller's blog post entitled *So You Want to Use Python on the Mac?* probably summarizes my feelings the best: "I prefer compilation and self management, that and I’ve had issues with macports in the past. So, go ahead and install it, but don’t use it for python work." Again though, I have no personal experience with MacPorts so if it works for others then that's great. – Matthew Rankin Sep 18 '09 at 02:01
  • Minimalism is fine! And I generally agree with Jesse's recommendations. But the point here is that you're recommending building a sledge hammer by hand to swat a pesky fly. Unfortunately, because it has C code and 3rd party lib dependencies, installing PIL on OSX has been problematic for a long time; with the transition of 10.6 to 64-bit, dropping of PPC, and a new GCC and SDKs, new twists were added but it's seldom necessary to rebuild all of Python to solve a problem with one package. (BTW, unlike Fink, MacPorts is strictly a source distribution so everything gets compiled locally.) – Ned Deily Sep 18 '09 at 04:33
3

10.6 Snow Leopard install PIL without the hassle and without keeping MacPorts :)

Step 1: Install MacPorts
Step 2: sudo port install py26-pil
Step 3: mv /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/* /Library/Python/2.6/site-packages/
Step 4: Uninstall MacPorts

Best of both worlds?

jriskin
  • 491
  • 2
  • 14
  • That step three is dangerous particularly with a space before that asterisk. It will grab whatever files from whatever directory you are in (cd) and move them to /Library/Python/2.6/site-packages/. – Regis Frey Jan 06 '11 at 03:51
  • Thanks, I got rid of the errant space. I forget some people might just cut and paste. It was more to illustrate the method :) – jriskin Jan 07 '11 at 20:56
2

Following steps worked for me:

$ brew install pip
$ export ARCHFLAGS="-arch i386 -arch x86_64"
$ pip install pil
petermanser
  • 249
  • 3
  • 9
1

IT seems to me that the "No such file" is conjunction with stdarg.h is the most interesting error. There seems to be a header file missing. I don't know how to make sure it's installed on OS X, so this only half an answer, sorry about that, but maybe it pushes you in the right direction.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • Hmm, the error says: "/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory". Yet when I navigate to "/Developer/SDKs/MacOSX10.4u.sdk/usr/include/", I can indeed see that stdarg.h is there – Mike Lawrence Sep 17 '09 at 12:15
  • @Mike isn't the file that's not found `#include`d from inside stdarg.h? It looks like the "4:25" refers to line number in stdarg.h. – Eric O. Lebigot Sep 17 '09 at 12:21
1

May be you should try pre-build universal binaries from pythonmac site

http://pythonmac.org/packages/py25-fat/index.html

These are for python2.5 , with python2.5 included(so may or may not be usable for you), I have been using it since I had problem using self build PIL with py2app.

Anurag Uniyal
  • 85,954
  • 40
  • 175
  • 219
1

I found a simpler method. sudo port install python26 sudo port install python_select

Then use python_select set python26 as default.

Then just install PIL as normal.

1

I was able to get PIP installed with SL's Python using these instructions:

http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/

shacker
  • 14,712
  • 8
  • 89
  • 89
0

On OS X Lion with current XCode and no gcc-4.0 I'm able to get around the missing stdard.h error by setting the follow environment variables:

export CC="/usr/bin/llvm-gcc-4.2"

I can't say I understand why this works.

By the way this works for the Pillow fork of PIL too.

scottynomad
  • 1,351
  • 11
  • 9
0

Do you have XCode (comes on the Snow Leopard disc) installed? There are some key components (most notably GCC) that need to be installed which XCode handles for you.

  • Yup, XCode is installed with the developer tools during the original Snow Leopard install. I've even tried re-installing the developer tools from the Snow Leopard disc, this time adding the 10.4 SDK in addition to the default 10.5 & 10.6 SDKs, but I still get the same errors afterwards. – Mike Lawrence Sep 17 '09 at 11:50
0

Solved in 2 steps:

Step 1: Uninstalled and Installed Xcode, suggested here: http://binarylionstudios.com/blog/2011/01/30/error-stdarg.h-no-such-file-or-directory/

to remove Xcode properlly follow this answer: How to fully remove Xcode 4

sudo /Developer/Library/uninstall-devtools --mode=all

use the install Xcode.app after you restart your mac

Step 2: after xcode was reinstalled, the installation failed

unable to execute gcc-4.2: No such file or directory PIL

to resolve that i followed this post: http://aravir-rose.blogspot.com/2011/12/installing-python-27s-imaging-library.html

Good luck!

Community
  • 1
  • 1
Yogev Shelly
  • 1,373
  • 2
  • 13
  • 24