I had the same problem, looks like a bug in Mako Templates for Windows. Providing the template as a string instead of a file reference (as shown below) solved the problem.
with open('code.template') as f:
templateStr = f.read()
template = mako.template.Template(templateStr)