Installing Python and Tkinter on MacOS X

For Tkinter you have two choices: a native "Aqua" version, or a version that runs with X11 or some other "X server". On the whole, the native version is easier to install and use (copy and paste "just work", and you don't have to run X11 before starting a script). However, it also has some cosmetic bugs (though many were fixed in Tcl/Tk 8.4.11) and is slow to launch.

Aqua Tkinter

X11 Tkinter

These instructions are for installing a new Tcl/Tk and Python from source. A shortcut well work considering is to use MacPorts or fink. Either will do the whole thing for you. It may be also possible to get MacPython to talk to X11 Tkinter, but I'm not sure how to do it and it almost certainly requires to to build or get hold of a new _tkinter.so library.

Warning: these instructions are old and may be outdated. I've not tried this since Python 2.3.

Preliminaries

Notes

Install readline version 4.3 from source

Note: the fix is needed because in the MacOS X 10.1->MacOS X 10.2 transition ncurses stuff was moved from the System library to external libraries and the process for dynamic libraries changed. The readline 4.3 process has not been updated to reflect this. Thanks to Dan Wolfe for the information and the readline 4.3 installation fix.

Install tcl and tk from source

Comments: the relevant README is in tkvers/unix/

Install Python from source

Test the basic installation

% cd ../Python-vers
% limit stacksize 2048   # for the re tests to succeed
# ulimit -s 2048 # use this instead for the bash shell
% make test

Fix your environment

The default python will be the one that Apple supplied. Modify your .cshrc to fix this (if you use the bash shell, you'll need to modify a different file and adjust these instructions):

Modify ~/.cshrc to include the following lines:

# this line makes your /usr/local/bin unix utilities override Apple's defaults:
setenv PATH "/usr/local/bin:"$PATH

Try it out

Launch X11. Then:
% source .cshrc  # or close the Terminal window and start another one
% rehash	# notifies tcsh that items on the path have changed
% python
>>> import Tkinter
>>> root = Tkinter.Tk()
you should see a new window in X11.

You're done!

History

2006-10-27. Updated Aqua Tcl/Tk installation instructions.

2004-05-21. Removed some incorrect aqua-isms from the X11 instructions and generally cleaned up the text.

Russell Owen
University of Washington
PO Box 351580
Seattle, WA 98195-1580
rowen u washington edu
     @ .          .