PyObjc 2: Leopard, Python 2.5.1 and You.

So, most everyone know that Apple released OS/X Leopard a bit ago – I was on the early adopter train, and have not had any problems (except for the occasional spaces crash because I mash buttons fast).

One of the cooler things that came out with Leopard was a completely overhauled PyObjC built-in. Including Webkit bindings, and many other things (see here and here for more details), a built-in version of twisted and many other things.

However, I was a moron. I was knee-deep in debugging a problem and compulsively replaced my came-with-leopard version of Python with the python.org python 2.5.1 build. (Anyone with tips on how to undo this, please let me know).

Once I dropped in the 2.5.1 version: poof. I managed to wipe out all of the delicious stuff built into my shiny new OS, which made me a sad panda. Once the PyObjC 2.0 stuff hit the PyObjC SVN tree (here) though, I was filled with hope that I could at least restore the PyObjC stuff.

Alas! It was not to be. Come to find out, there’s a hard coded string in the macpython makefile which causes the pyobjc build to use the wrong SDK and puke and die. After much wailing and gnashing of teeth, I gave up not realizing what the problem was. You should see a problem like this:

C compiler: gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3

compile options: '-I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c'
gcc: Modules/_Foundation_nscoder.m
Modules/_Foundation_nscoder.m: In function ‘imp_NSCoder_encodeArrayOfObjCType_count_at_’:
Modules/_Foundation_nscoder.m:220: error: ‘NSUInteger’ undeclared (first use in this function)
Modules/_Foundation_nscoder.m:220: error: (Each undeclared identifier is reported only once
Modules/_Foundation_nscoder.m:220: error: for each function it appears in.)
Modules/_Foundation_nscoder.m:220: error: syntax error before ‘count’
Modules/_Foundation_nscoder.m:228: error: syntax error before ‘i’
Modules/_Foundation_nscoder.m:249: error: ‘count’ undeclared (first use in this function)
Modules/_Foundation_nscoder.m:256: error: ‘i’ undeclared (first use in this function)

However, last night I was snowed-in at work and in between bug fixes for work, I managed to dig up a post (with fix) on the issue I was having (thanks Barry).

The short answer is sync the tree from subversion, and then edit the following file:

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config/Makefile

And remove the “-isysroot /Developer/SDKs/MacOSX10.4u.sdk” chunk of text. Drop into the sync’ed svn tree and run the 02-develop-all.sh script. Now I can happily import WebKit:

Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import WebKit
>>>

  • Erich Phillip
    I did very much the same thing, and until I found your post, I was at a loss as to how to get around the PyObjC problem. Did you try using 'Pacifist' (http://www.charlessoft.com/) to reinstall PyObjC? I am going to try that, to see if I can restore Python, including PyObjC, to the state it comes in with Leopard. It is good to know, however, that if this does not fix my problem, I can try your solution.

    I will let you know
  • See the comments above - the post by Anonymous worked, removing the altered path from .bash_profile worked great, the from the site version of python does not alter the framework version, in fact you can load it with /usr/bin/python
  • Dewww
    I don't know if this is a good thing or not, but I had installed Activestate python overtop of the /Library/Frameworks/Python.framework version and couldn't import objc. After much nashing (as you say) I renamed /Library/Frameworks/Python.framework and started over with a sudo cp -Rp /System/Library/Frameworks/Python.framework /Library/Frameworks/Python.framework and now import objc works just fine, even import WebKit
  • Barry Wark
    Since I'm somewhat responsible for this fix, I should note that deleting thie "-isysroot /Developer/SDKs/MacOSX10.4u.sdk" line will have unforeseeable and potentially bad consequences down the road. Perhaps a better solution is to build the MacPython from source on Leopard so that it uses the 10.5 SDK. Although you'll have to rebuild all your extensions, this is probably the better way to go. There's a 10.5 SDK build available on my web site (http://rieke-server.physiol.washington.edu/~bar...). Give it a try, though I can't guarantee anything. It will install over the existing Python.framework (I don't know of any way around this since the python version is the same), so you should move your old one to somewhere safe before installing. You'll then have to re-install (and build) any modules and extensions that were installed in site-packages.

    pyobjc2 will build and run just fine with this build.
  • It should be noted that the built in version of twisted is actually embarrassingly incomplete and outdated. (It consists only Twisted Core 2.4 and Twisted Words.)

    A package and some installation notes can be found via http://twistedmatrix.com/trac/wiki/Packages#Leo...

    I'll get back to you on how best to uninstall the MacPython 2.5.1 package. (The hard coded path is because it was built for 10.4)

    -dreid
  • It's not just un-install - it's restoring to the original framework version that shipped w/ leopard
  • They don't go to the same locations ... the original framework is still in /System/Library/Frameworks/Python.framework.

    You'll want to go through /Library/Receipts/MacPython.mpkg and delete all the files referenced in the *.bom files

    http://www.macworld.com/article/47341/2005/10/v...

    I don't remember if the MacPython package uses any postflight scripts to set up symlinks and stuff like that though.
  • Anonymous
    The postflight script adds /Library/Frameworks/Python.framework/Versions/Current/bin to your PATH, but doesn't touch the system syslinks (at least not as far as I can tell). You can get rid of the python.org install just by removing/renaming the /Library/Frameworks/Python.framework directory, and optionally editing your .bash_profile to take the now-defunct directory out of your PATH.
  • Interesting, I may try this just to see if it will all work :)
blog comments powered by Disqus