ImportError:Jinja2模板中没有名为_sqlite3的模块

时间:2013-04-23 11:08:34

标签: sqlite google-app-engine jinja2

我刚刚从Python 2.5迁移到2.7运行时,我编写的大多数服务器都运行良好。然而,我偶尔看到这个奇怪的堆栈跟踪(我为了简洁而将其砍掉):

ERROR    2013-04-23 10:40:15,598 wsgi.py:235]
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2-2.6/jinja2/environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "templates/querystart.html", line 30, in top-level template code
{% for session in sessions %}
ImportError: No module named _sqlite3

我自己没有导入sqlite3,我不依赖它。调用它的代码非常简单(可能接近于愚蠢的一面):

class UserIdQuery(BaseHandler):
def get(self):
    sessionQuery=Session.all().order("userid")
    template_values = {
        'sessions': sessionQuery,
    }
    self.render_template('querystart.html',**template_values)

以上简单扩展了以下内容(取自非常有用的迁移教程)

class BaseHandler(webapp2.RequestHandler):
@webapp2.cached_property
def jinja2(self):
    return jinja2.get_jinja2(app=self.app)

def render_template(self, filename, **template_args):
    self.response.write(self.jinja2.render_template(filename, **template_args))

任何人都知道可能触发导入错误的原因是什么?谢谢,

2 个答案:

答案 0 :(得分:1)

Appengine使用sqlite作为数据存储区,我的赌注是你在OSX上安装的python2.7缺少sqlite二进制库。做一个快速测试,启动一个python解释器(appengine之外)并尝试导入sqlite3

$ python
Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> 

如果失败,您就知道安装了2.7运行时不完整。

答案 1 :(得分:0)

我遇到了同样的问题并修复了它。

我运行的是从Ninite.com安装的python 2.7.3。

卸载python,直接从python.org下载并安装了2.7.5安装程序,问题已经消失。

相关问题