Thursday, 10 October 2013

Get Python IDLE to work on your Mac

An out of the box Mac comes with Python and a development environment called IDLE. Unfortunately it doesn't work very well e.g. raw_input() command causes it to hang and there are some other serious problems. Here's an alternative and a quick solution...
IDLE relies on a scripting language called Tcl and a set of GUI elements known as Tk.  Macs come with Apple's own versions of Tcl/Tk that are badly implemented - this is the cause of the problems with IDLE.

The alternative to Python's IDLE

Since the standard Mac IDLE has problems it's good to have an alternative if you can't use the fix I give below. So here it is.  Use a text editor to create and edit your code and execute it from the Terminal e.g.:
python helloworld.py

The .py extension indicates that it is python code and text editors, such as the awesome Sublime, colour source code to help readability but must be able to discover which language it is written in by looking at the extension.

The fix for Python's IDLE

The fix for the problems requires replacing Apple's Tcl/Tk. Ned Deily on stackoverflow suggests using ActiveTcl 8.5 however a new version (currently 3.4.0a3) of Python has been released that comes with its own Tcl/Tk. Installing this version of Python appears to fix the problems with running IDLE on a Mac including the raw_input() hang although it is currently only an alpha release.