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
- Download and install MacPython from the pythonmac.org. This same site also includes many useful installers for useful python packages.
- At this point you have a MacPython that will use the nasty built-in version of Tcl/Tk. If you want to do better, continue...
- Download and install Aqua Tcl/Tk. At the time of this writing 8.4.13 is current (8.4.14 has been released but a Mac binary is not yet available), and I prefer 8.4.11 because 8.4.13 has trouble keeping track of the mouse position. Mac binary installers are available from ActiveState.
- You have to modify _tkinter.so to see your Tcl/Tk (a problem I hope will eventually be solved by the Mac python packagers). Run fixtkinter, a simple python script, to do the job. The header of the script explains what it's doing.
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
- Install the Apple Developer Tools, if you have not already done so.
- Install X11 and the X11 SDK (or some other X server) if you have not already done so. X11 and the X11 SDK are an optional part of the 10.3.x and 10.4.x installation. If you installed MacOS X 10.3 without installing X11 you will have to use something like Pacifist to extract the appropriate installers (since I don't know of any standalone installer from Apple).
- Pick a directory to contain all your unix source code. This should be owned by you, not a system directory, so you can easily read, write, execute and delete files. It should have no spaces in its path name (else the Tcl/Tk installation will fail). Put all downloaded files and unpacked archives there. In the following instructions "..." refers to this directory.
Notes
- Commands with a leading "%" indicate commands to be typed at the terminal. Do not type the %
- You may edit files however you choose, but the files typically ought to have unix line endings. A reasonable option is the included pico command-line editor (type pico at the command-line prompt).
- If you run into problems installing any package below, once you figure out how to get around them, I recommend deleting the source directory and unpacking a new one. Some make files include cleanup code (e.g. make clean or the like) but not all do.
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
@ . .