Defer imports to a later stage so Jinja2 does not become a build dependency. Fixes #3293.