Wednesday, December 15, 2010

More troubleshooting: XCode and PyObjC

I was going to tell you how I got PyObjC and XCode working together on my third (office) machine. The symptoms are shown in the above screenshot. The red Failure thingies are saying that none of the names defined in Python/Python.h are recognized, like it couldn't find the header file. But the "missing required architecture ppc" warning suggested to me (since I have an i386 iMac), that I should play with the Project settings.

And I did something to those settings that fixed (this part of) it, but I'm not positive now because it's been a couple of days and I can't recreate the failure. The settings I have that work are:

So we'll just mark that down as a likely trouble spot to look at, for next time. The second issue was the same kind of failure that I saw on the other machine (here), though not the same Python, naturally:

Traceback (most recent call last):
File "", line 12, in
import objc
ImportError: No module named objc

where an inserted print sys.version statement gave:

2.6.4 (r264:75706, Mar  3 2010, 09:38:49) 

It's not this:

$ /usr/bin/python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)

So where is 2.6.4 from Mar 3 2010, 09:38:49 ? After a long search,

cd /Library/Frameworks/Python.framework/Versions/2.6/bin
Python 2.6.4 (r264:75706, Mar 3 2010, 09:38:49)

So.. we've got a Python in /Library and that's what is being used..
How did it get there? I don't remember.. Why did XCode choose it? No idea. Since it was in /Library rather than /System, and I was having difficulty with easy_install, I decided to try more radical surgery:

cd /Library/Frameworks
sudo rm -rf Python.framework
Don't try that at home!
The patient survived. And XCode switches to:

2.5.4 (r254:67916, Jun 24 2010, 21:47:25)

Old, but the XCode project runs. And I can't find that Python anywhere!

1 comment:

William said...

Thanks for the solution. This is crazy! I bet your solution would work on my computer, but I'm running a later version of python for a reason and don't want to delete it in favor of some Steve Jobs-sponsored antediluvian version.

There might be an easier and safer solution. XCode simply doesn't know where to find objc. Is there a way to add the older 2.5 (or whatever version had objc) framework files to the search path?

I'm going to check into that possibility soon, but can't now as I'm on my iPhone at the moment.

Or, if you've since found a more elegant solution, please share.