ImportError:没有名为_sqlite3的模块

时间:2010-04-19 05:34:12

标签: python google-app-engine sqlite pyevolve

我正在为Google App Engine撰写文章,我的本地测试收到以下错误:

-->  --> -->

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3185, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3128, in _Dispatch
    base_env_dict=env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 515, in Dispatch
    base_env_dict=base_env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2387, in Dispatch
    self._module_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2297, in ExecuteCGI
    reset_modules = exec_script(handler_path, cgi_path, hook)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2193, in ExecuteOrImportScript
    exec module_code in script_module.__dict__
  File "C:\Users\Chris Reade\Documents\SI 182\Final\geneticsalesman\Final.py", line 7, in <module>
    from pyevolve import DBAdapters
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1922, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1824, in FindAndLoadModule
    description)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1775, in LoadModuleRestricted
    description)
  File "C:\Users\Chris Reade\Documents\SI 182\Final\geneticsalesman\pyevolve\DBAdapters.py", line 21, in <module>
    import sqlite3
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1922, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1824, in FindAndLoadModule
    description)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1775, in LoadModuleRestricted
    description)
  File "C:\Python26\lib\sqlite3\__init__.py", line 24, in <module>
    from dbapi2 import *
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1922, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1824, in FindAndLoadModule
    description)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1775, in LoadModuleRestricted
    description)
  File "C:\Python26\lib\sqlite3\dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

我的python方向有一个sqlite3的lib文件,但我不知道它为什么找不到它。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

App Engine SDK会努力为您在真实 App Engine(在Google服务器上)失败的任何模块导入提供错误。后者不支持SQlite,所以给你错误就是SDK很好的说法“你将无法在真正的Google App Engine服务器上部署这些代码”!

答案 1 :(得分:0)

当一个人想要第一次使用sqlite3时,App引擎尝试引发错误。发生这种情况并不是因为App Engine(本地)不允许将sqlite3用作备用数据库,这是因为生产级别不支持sqlite3。因此,App引擎正在基于其目的来劝阻您不要使用sqlite3,以便您不会误以为使用sqlite3部署App。
因此,要在本地App Engine中使用sqlite3,您需要将sqlite3列入白名单,如下所示:

转到 C:\ Program Files(x86)\ Google \ google_appengine \ google \ appengine \ tools \ devappserver2 \ python \ runtime \ sandbox.py
打开文件,您会发现一个常量变量_WHITE_LIST_C_MODULES声明为:

  _WHITE_LIST_C_MODULES = [
        'array',
        '_ast',
        'binascii',
        '_bisect',
         .
         .
         .,
]

然后添加sqlite3,如下所示:

  _WHITE_LIST_C_MODULES = [
                'array',
                '_ast',
                'binascii',
                '_bisect',
                 .
                 .
                 .,
                _sqlite3,
        ]

我希望这对您有用。