Wednesday, December 15, 2010

One Python or two

OS X and Python and PyObjC make a great combination for the "hobbyist programmer." Which is Apple's original market, as I recall.

And they may even be right for other apps, say those developed for an academic environment, despite bbum's disavowal (here and here). Rapid prototyping is a huge advantage, and you might consider doing new projects quickly in PyObjC, and then converting them to standard Objective-C.

A perennial issue with Python (and I guess the web generally) is to discern what's current and useful today rather than ancient history. You have to be a detective..

A "MacPython page" is still on the web (here).

All that stuff is old (though some files have new timestamps), and you shouldn't use it, unless you're still running a very old OS X version. But if you were naive you might not notice---possibly you might not even know that Python is already installed on your machine.

There are old PyObjC pages around too (e.g. SourceForge here). Don't use that!

You might even go to's download page (here). I would recommend not using that either unless you're sure you know what you are doing.

I got the project and file templates using svn:

svn co

and I even checked out the trunk, but I have no idea how to build it yet.

PyObjC comes with the Apple Python:

$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import objc
>>> objc.__version__

Use the templates as discussed previously (here and here). You should be good to go.

Sometimes things don't work. Actually, of 3 machines where I installed the templates, 2 of them don't work. On one of these, the failure was due to the fact that at some point (probably with's python), somehow I installed over the standard Python.framework at:


Luckily, that one had easy_install, so I could just use it to grab and install PyObjC, and after that XCode and the new templates worked fine (here).

The other machine had two additional issues: there was a conflict between what the template called for and what was present in the SDK. It also had the "wrong Python" problem, and in that case, no easy_install. And if you don't already have easy_install installed, trust me, it ain't easy!

That's for another time.

You get conflicting advice about whether to install "another" Python or not. The advantage of having one Python is there is no confusion about what's running, and the XCode issues of the wrong Python being called don't come up.

On the other hand, some of these packages have very specific requirements for what versions their dependencies need to be, and it can be frustrating trying to install something like SciPy. I've done it myself (here, with links), and using MacPorts (here), but only by adding another Python installation (or two). Unfortunately, there is not a simple answer to this question.