To clarify, are you trying to run the script via GIMP or on its own via Python from a command-line? The latter method's correct; the description of it in the first post as a "GIMP script" is a bit misleading.