views:

9541

answers:

10

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 and (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. Any help would be greatly appreciated!

A: 

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.

cpharmston
Mike
+1  A: 

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
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
@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.
EOL
C-compiler error messages take a lot of interpreting... :-/
Lennart Regebro
A: 

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
No dice. The python2.5 binary installer for PIL requires python2.5 to be installed.
Mike
yes that i mentioned in answer, thinking you may/can switch to 2.5
Anurag Uniyal
+9  A: 

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 so no additional installs are needed.

Ned Deily
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
+4  A: 

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
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
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
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
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
+1  A: 

Hi, 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  A: 

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
+1  A: 

I tried to install PIL on the default Python 2.6.1 using Matthew's answer. It, however, fails at mkvirtualenv with the following error message.

$ mkvirtualenv pil-test
New python executable in pil-test/bin/python
Installing setuptools.............done.
  Complete output from command /Users/yoichi/.virtualenvs/pil...ython /Users/yoichi/.virtualenvs/pil...stall /Library/Python/2.6/site-packa...ar.gz:
  Processing pip-0.6.1.tar.gz
Running pip-0.6.1/setup.py -q bdist_egg --dist-dir /var/folders/ZZ/ZZ7tAIJsFU8FDfPPp7H53++++TM/-Tmp-/easy_install-Jzrqqw/pip-0.6.1/egg-dist-tmp-zq0POm
error: Setup script exited with error: SandboxViolation: open('pip.egg-info/PKG-INFO', 'w') {}

The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.

This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand.  Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.
----------------------------------------
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 8, in 
    load_entry_point('virtualenv==1.4.3', 'console_scripts', 'virtualenv')()
  File "/Library/Python/2.6/site-packages/virtualenv-1.4.3-py2.6.egg/virtualenv.py", line 528, in main
    use_distribute=options.use_distribute)
  File "/Library/Python/2.6/site-packages/virtualenv-1.4.3-py2.6.egg/virtualenv.py", line 620, in create_environment
    install_pip(py_executable)
  File "/Library/Python/2.6/site-packages/virtualenv-1.4.3-py2.6.egg/virtualenv.py", line 390, in install_pip
    filter_stdout=_filter_setup)
  File "/Library/Python/2.6/site-packages/virtualenv-1.4.3-py2.6.egg/virtualenv.py", line 589, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/yoichi/.virtualenvs/pil...ython /Users/yoichi/.virtualenvs/pil...stall /Library/Python/2.6/site-packa...ar.gz failed with error code 1
ERROR: Environment '/Users/yoichi/.virtualenvs/pil-test' does not contain an activate script.

BTW, the default Python 2.6.1 is install in /System/Library/Frameworks/Python.framework/Versions/2.6/bin/, not as shown in the instruction.

Also, pip, virtualenv and virtualenvwrapper_bashrc got all installed in /usr/local/bin.

These are all different from what Matthew suggests otherwise. I have adjusted the bash_profile accordingly, of course.

Any suggestion?

Yoichi
+1  A: 

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
A: 

I still can't get this working using gcc-4.0, any suggestions?

$ export CC=/usr/bin/gcc-4.0 $ sudo python setup.py install running install running build running build_py running build_ext --- using frameworks at /System/Library/Frameworks building '_imaging' extension 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/opt/local/include -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 In file included from /usr/include/math.h:26, from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyport.h:235, from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:58, from _imaging.c:75: /usr/include/architecture/ppc/math.h:666: warning: conflicting types for built-in function ‘scalb’ In file included from /usr/include/stdarg.h:4, from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/unicodeobject.h:4, from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:85, from _imaging.c:75: /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory _imaging.c:3017: warning: initialization from incompatible pointer type _imaging.c:3077: warning: initialization from incompatible pointer type In file included from /usr/include/architecture/i386/math.h:626, from /usr/include/math.h:28, from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyport.h:235, from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:58, from _imaging.c:75: /usr/include/AvailabilityMacros.h:108:14: warning: #warning Building for Intel with Mac OS X Deployment Target < 10.4 is invalid. In file included from /usr/include/stdarg.h:4, from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/unicodeobject.h:4, from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:85, from _imaging.c:75: /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory _imaging.c:3017: warning: initialization from incompatible pointer type _imaging.c:3077: warning: initialization from incompatible pointer type lipo: can't figure out the architecture type of: /var/tmp//ccnfd5FR.out error: command 'gcc' failed with exit status 1

Jason
@Jason: it's a bad idea to ask a question by adding a new answer; I just happened to see this by accident. Either add a comment to an existing question/answer or, better, open your own new question. With that much traceback, you also need to use the text editing tool: there's a `code` format to use to make it readable.
Ned Deily