Fixing the PyAverager sample on ADC

A few days ago I ran across this old sample on ADC: Using PyObjC for Developing Cocoa Applications with Python. PyObjC is the Python/Objective-C bridge. Similiarly, there is also a Ruby bridge, RubyCocoa. Personally, I find the possibility of using Python or Ruby to write Cocoa applications more appealing than using Objective-C.

In any case, the example is pretty straight forward and even has helpful (necessary?) videos for the more involved steps. After completing everything, however, you’ll find that it will not build:

Compile error

The build tool is complaining about not finding usr/bin/env python. Apparantly, the PyObjC Cocoa template for is geared more towards looking for Python in a traditional Unix environment. This is an easy fix though.

Simply run Terminal and type in which python to find the correct path to Python on your Mac OS X system:


Copy-and-paste your python path to the top line of the file while keeping the first two characters:


After saving your changes, re-building and running your app, you’ll notice that you are now presented with a runtime error:

Runtime error

This requires another simple fix. You’ll have to add an import line to the file. The new line is highlighted below:

# PyAverager

from PyObjCTools import NibClassBuilder, AppHelper

info = NSBundle.mainBundle().infoDictionary()[u'PyObjCXcode']

for nibFile in info[u'NIBFiles']:

for pythonModule in info[u'Modules']:


if __name__ == '__main__':

Another round of saving/re-building and you’ll now be able to run the sample as expected:

Running PyAverager

Sliding Sidebar