June 17, 2008
The mysterious “ImportError: cannot import name cache”
The scenario: I'm packaging a CherryPy server with py2exe, using Mako as my template engine. So I create my exe file, and fire up the app, and get this 500 Mako error:
Traceback (most recent call last):
File "cherrypy\_cprequest.pyo", line 551, in respond
File "cherrypy\_cpdispatch.pyo", line 24, in __call__
File "main.py", line 210, in index
File "mako\lookup.pyo", line 70, in get_template
File "mako\lookup.pyo", line 112, in __load
File "mako\template.pyo", line 74, in __init__
File "…", line 1, in <module>
ImportError: cannot import name cache
Since the app was working fine without py2exe, I brilliantly deduced that maybe something was getting broken in the packaging process.
It turns out that I need to include "mako.cache" in my packages, as pointed out by this blog post.
So the relevant section of my setup dictionary now looks like this:
"pywin.debugger.dbgcon",
"pywin.dialogs",
"pywin.dialogs.list",
"win32com.server",
"Tkinter"]
packages=["email", "lxml", "mako.cache"]
options = dict(optimize=2,
dist_dir=comp_name,
excludes=excludes,
packages=packages)
setup_dict['options'] = {"py2exe":options}
Everything's working now — lovely stuff!
Googling on this error failed to produce any hits, so I had to (gasp!) do some actual research to figure this out. Here's hoping that I can save the next poor soul from that horror.
Thanks very much. You did save this poor soul from checking.
Glad you found it useful. Nowadays it’s second nature for me to Google any error messages that I find, and I get a moment of disorientation when no results come up. :)