PyObjc 2: Leopard, Python 2.5.1 and You.

by jesse in , ,

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