Intro To Using PyObjC

Overcoming Newbie Hurdles when using PyObjC, Xcode and Interface Builder

Contents

Introduction

Python is a great fit for the Macintosh. It's an elegant language for an elegant computer. I tip my hat to the guys who made the PyObjC bridge, for it springs the doors wide open to what you can do with Python on a Mac.

This page includes links to obtaining and installing PyObjC and other useful tools. This is followed by step-by-step instructions that will help anyone just starting PyObjC get over those first set of hurdles.

The intended audience for this document is a Python programmer who have installed PyObjC, but didn't quite make it through the introductory tutorial included in the distribution. I, for one, wasn't too familiar with Interface Builder. This document assumes you already know how to program in Python, know your way around a Mac and have admin priviledges. You should also have experience with programming using an IDE and have read Apple's documentation for Xcode and Interface Builder. For more background reading, try StartCocoa, a collection of PyObjC and Cocoa information sources.

Document history:

Software

This document assumes that you are running Mac OS X 10.4 and have installed the designated versions of the following software:

MacPython 2.4.3
Universal-MacPython-2.4.3-2006-04-07.dmg
Xcode 2.3
http://developer.apple.com
PyObjC 1.4
pyobjc-1.4-python2.4-macosx10.4.dmg

The First Hurdle - Verifying Installation

Test that things installed properly. Open a Terminal, start an interactive Python session from the command line. Check in the opening credits that it's the 2.4.3 version that is running. If it is not the version you installed, set the path to your version so it is early on in your PATH environment variable. For me, this meant adding the following line to ~/.cshrc (your shell may vary):

setenv PATH "/Library/Frameworks/Python.framework/Versions/2.4/bin:"$PATH

If you had to change your shell configuration file, be sure the OS knows about the change. Either logout and login (boo!) OR run a command equivalent to the following (your shell may vary):

% source ~/.cshrc

Now, to check that PyObjC installed correctly, type the following at at the interactive prompt:

>>> import Foundation, AppKit
>>> AppKit.NSBeep()

If the import happened without complaint and you heard the system beep, you're most likely good to go; if not, you'll have to get help elsewhere. Congrats, that was a legitimate call into Apple's Cocoa libraries! Feeling tingly yet? We don't need Terminal any more, you can hide it.

The Second Hurdle - Xcode

The Third Hurdle - Interface Builder

The Fourth Hurdle - Writing Valid PyObjC Code