PyObjc 2: Leopard, Python 2.5.1 and You.

December 14th, 2007 § 11 comments

So, most every­one know that Apple released OS/X Leop­ard a bit ago — I was on the early adopter train, and have not had any prob­lems (except for the occa­sional spaces crash because I mash but­tons fast).

One of the cooler things that came out with Leop­ard was a com­pletely over­hauled PyObjC built-in. Includ­ing Webkit bind­ings, and many other things (see here and here for more details), a built-in ver­sion of twisted and many other things.

How­ever, I was a moron. I was knee-deep in debug­ging a prob­lem and com­pul­sively replaced my came-with-leopard ver­sion of Python with the python.org python 2.5.1 build. (Any­one with tips on how to undo this, please let me know).

Once I dropped in the 2.5.1 ver­sion: poof. I man­aged to wipe out all of the deli­cious 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 make­file which causes the pyobjc build to use the wrong SDK and puke and die. After much wail­ing and gnash­ing of teeth, I gave up not real­iz­ing what the prob­lem was. You should see a prob­lem 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

com­pile options: ‘-I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 –c’
gcc: Modules/_Foundation_nscoder.m
Modules/_Foundation_nscoder.m: In func­tion ‘imp_NSCoder_encodeArrayOfObjCType_count_at_’:
Modules/_Foundation_nscoder.m:220: error: ‘NSUIn­te­ger’ unde­clared (first use in this func­tion)
Modules/_Foundation_nscoder.m:220: error: (Each unde­clared iden­ti­fier is reported only once
Modules/_Foundation_nscoder.m:220: error: for each func­tion it appears in.)
Modules/_Foundation_nscoder.m:220: error: syn­tax error before ‘count’
Modules/_Foundation_nscoder.m:228: error: syn­tax error before ‘i’
Modules/_Foundation_nscoder.m:249: error: ‘count’ unde­clared (first use in this func­tion)
Modules/_Foundation_nscoder.m:256: error: ‘i’ unde­clared (first use in this func­tion)

How­ever, last night I was snowed-in at work and in between bug fixes for work, I man­aged to dig up a post (with fix) on the issue I was hav­ing (thanks Barry).

The short answer is sync the tree from sub­ver­sion, and then edit the fol­low­ing file:

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

And remove the “-isys­root /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 hap­pily 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
>>>

  • http://dreid.org/ David Reid

    It should be noted that the built in ver­sion of twisted is actu­ally embar­rass­ingly incom­plete and out­dated. (It con­sists only Twisted Core 2.4 and Twisted Words.)

    A pack­age and some instal­la­tion notes can be found via http://twistedmatrix.com/trac/wiki/Packages#Leo

    I’ll get back to you on how best to unin­stall the MacPython 2.5.1 pack­age. (The hard coded path is because it was built for 10.4)

    –dreid

  • jnoller

    It’s not just un-install — it’s restor­ing to the orig­i­nal frame­work ver­sion that shipped w/ leopard

  • http://dreid.org/ David Reid

    They don’t go to the same loca­tions … the orig­i­nal frame­work is still in /System/Library/Frameworks/Python.framework.

    You’ll want to go through /Library/Receipts/MacPython.mpkg and delete all the files ref­er­enced in the *.bom files

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

    I don’t remem­ber if the MacPython pack­age uses any post­flight scripts to set up sym­links and stuff like that though.

  • Anony­mous

    The post­flight script adds /Library/Frameworks/Python.framework/Versions/Current/bin to your PATH, but doesn’t touch the sys­tem sys­links (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 direc­tory, and option­ally edit­ing your .bash_profile to take the now-defunct direc­tory out of your PATH.

  • jnoller

    Inter­est­ing, I may try this just to see if it will all work :)

  • Barry Wark

    Since I’m some­what respon­si­ble for this fix, I should note that delet­ing thie “-isys­root /Developer/SDKs/MacOSX10.4u.sdk” line will have unfore­see­able and poten­tially bad con­se­quences down the road. Per­haps a bet­ter solu­tion is to build the MacPython from source on Leop­ard so that it uses the 10.5 SDK. Although you’ll have to rebuild all your exten­sions, this is prob­a­bly the bet­ter way to go. There’s a 10.5 SDK build avail­able on my web site (http://rieke-server.physiol.washington.edu/~bar…). Give it a try, though I can’t guar­an­tee any­thing. It will install over the exist­ing Python.framework (I don’t know of any way around this since the python ver­sion is the same), so you should move your old one to some­where safe before installing. You’ll then have to re-install (and build) any mod­ules and exten­sions that were installed in site-packages.

    pyobjc2 will build and run just fine with this build.

  • Dewww

    I don’t know if this is a good thing or not, but I had installed Actives­tate python over­top of the /Library/Frameworks/Python.framework ver­sion and couldn’t import objc. After much nash­ing (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

  • 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 prob­lem. Did you try using ‘Paci­fist’ (http://www.charlessoft.com/) to rein­stall PyObjC? I am going to try that, to see if I can restore Python, includ­ing PyObjC, to the state it comes in with Leop­ard. It is good to know, how­ever, that if this does not fix my prob­lem, I can try your solution.

    I will let you know

  • jnoller

    See the com­ments above — the post by Anony­mous worked, remov­ing the altered path from .bash_profile worked great

  • 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 prob­lem. Did you try using ‘Paci­fist’ (http://www.charlessoft.com/) to rein­stall PyObjC? I am going to try that, to see if I can restore Python, includ­ing PyObjC, to the state it comes in with Leop­ard. It is good to know, how­ever, that if this does not fix my prob­lem, I can try your solution.

    I will let you know

  • http://jessenoller.com jnoller

    See the com­ments above — the post by Anony­mous worked, remov­ing the altered path from .bash_profile worked great, the from the site ver­sion of python does not alter the frame­work ver­sion, in fact you can load it with /usr/bin/python

What's this?

You are currently reading PyObjc 2: Leopard, Python 2.5.1 and You. at jessenoller.com.

meta