[英]OS X AppEngine - ImportError: No module named _sqlite3
UPDATE: This is a problem I am having with the 1.8.0 App Engine SDK on a fresh install of OS X 10.8.3. 更新:这是我在全新安装的OS X 10.8.3上使用1.8.0 App Engine SDK时遇到的问题。
First up - there's a bunch of questions on SO with a similar title. 首先 - 在SO上有一堆关于类似标题的问题。 I've checked them out, and I don't believe they answer my question.
我已经检查过了,我不相信他们回答了我的问题。 Mostly they recommend getting libsqlite3-dev and rebuilding python to get _sqlite3.so, but that's already where it should be:
大多数情况下,他们建议使用libsqlite3-dev并重建python以获取_sqlite3.so,但这已经是应该的位置了:
$ find / -name _sqlite3.so Password: ... /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_sqlite3.so /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/_sqlite3.so /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_sqlite3.so
The actual code that that causes app engine SDK to try to load that module is: 导致app引擎SDK尝试加载该模块的实际代码是:
remaining = TaskSetElement.all().filter('taskSet', ts_key).filter('complete', False).count()
Here's the SDK stack trace: 这是SDK堆栈跟踪:
File "~/dev/myApp/myApp/task.py", line 90, in completeTaskSetElement
remaining = TaskSetElement.all().filter('taskSet', ts_key).filter('complete', False).count()
File "~/dev/GAE/google_appengine/google/appengine/ext/db/__init__.py", line 2133, in count
result = raw_query.Count(limit=limit, **kwargs)
File "~/dev/GAE/google_appengine/google/appengine/api/datastore.py", line 1698, in Count
batch = self.GetBatcher(config=config).next()
File "~/dev/GAE/google_appengine/google/appengine/datastore/datastore_query.py", line 2754, in next
return self.next_batch(self.AT_LEAST_ONE)
File "~/dev/GAE/google_appengine/google/appengine/datastore/datastore_query.py", line 2791, in next_batch
batch = self.__next_batch.get_result()
File "~/dev/GAE/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 604, in get_result
return self.__get_result_hook(self)
File "/Users/colin/dev/GAE/google_appengine/google/appengine/datastore/datastore_query.py", line 2528, in __query_result_hook
self._batch_shared.conn.check_rpc_success(rpc)
File "~/dev/GAE/google_appengine/google/appengine/datastore/datastore_rpc.py", line 1222, in check_rpc_success
rpc.check_success()
File "~/dev/GAE/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 570, in check_success
self.__rpc.CheckSuccess()
File "/Users/colin/dev/GAE/google_appengine/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitImpl
self.request, self.response)
File "~/dev/GAE/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 200, in MakeSyncCall
self._MakeRealSyncCall(service, call, request, response)
File "~/dev/GAE/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 234, in _MakeRealSyncCall
raise pickle.loads(response_pb.exception())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1382, in loads
return Unpickler(file).load()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1090, in load_global
klass = self.find_class(module, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1124, in find_class
__import__(module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/__init__.py", line 24, in
from dbapi2 import *
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/dbapi2.py", line 27, in
from _sqlite3 import *
File "~/dev/GAE/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 856, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named _sqlite3
I've got a bunch of datastore code prior to this line that's executing fine. 我在这一行之前有一堆数据存储区代码执行正常。 I get the same problem running dev_appserver.py directly from the command line or in eclipse with pydev.
我直接从命令行或在带有pydev的eclipse中运行dev_appserver.py会遇到同样的问题。
From the command line, everything looks good: 从命令行,一切看起来都很好:
$ python Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> import _sqlite3 >>> import sys >>> print(sys.path) ['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'] >>>
This code snippet (running in app engine SDK) removes the app engine datastore code from the equation: 此代码段(在app引擎SDK中运行)会从以下等式中删除应用引擎数据存储区代码:
...
logging.info("Python Version: %s" % sys.version)
logging.info(filter(lambda p: 'lib-dynload' in p, sys.path))
import sqlite3
...
It outputs this: 它输出这个:
INFO 2013-05-26 05:55:12,055 main.py:38] Python Version: 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] INFO 2013-05-26 05:55:12,055 main.py:40] ['/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload'] ERROR 2013-05-26 05:55:12,058 cgi.py:121] Traceback (most recent call last): File "main.py", line 42, in import sqlite3 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/__init__.py", line 24, in from dbapi2 import * File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * File "~/dev/GAE/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 856, in load_module raise ImportError('No module named %s' % fullname) ImportError: No module named _sqlite3
Any ideas what the problem is? 有什么想法是什么问题? Thanks,
谢谢,
Colin 科林
It looks like adding '_sqlite3'
to the _WHITE_LIST_C_MODULES
list at line 742 in sandbox.py (which lives at /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python
on my machine) has worked for me for now. 将
'_sqlite3'
添加到sandbox.py中第742行的_WHITE_LIST_C_MODULES
列表中(位于/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python
在我的机器上)现在已经为我工作了。
To my uneducated eye it looks like CModuleImportHook
is incorrectly blocking the import of _sqlite3 and that modifying any one of the checks it has to return None
removes the error. 对于我没有受过教育的人来说,看起来
CModuleImportHook
错误地阻止了_sqlite3的导入并修改了它必须返回的任何一个检查None
删除错误。 Someone with more nous - please expand on what I've said or correct me! 有更多的人 - 请扩展我说的或纠正我!
That change may allow you to import _sqlite3 in your own code, which would be a mistake. 该更改可能允许您在自己的代码中导入_sqlite3,这将是一个错误。 Perhaps it needs a way to limit the import to dbapi2.py?
也许它需要一种方法来限制导入到dbapi2.py?
From you stack trace it shows you are trying to import sqlite in your main.py. 从堆栈跟踪中,它显示您正在尝试在main.py中导入sqlite。
Why are you doing this? 你为什么做这个?
Importing sqlite is not supported in appengine. appengine不支持导入sqlite。 sqlite is implemented with a binary library and you can't just import any old binary.
sqlite是用二进制库实现的,你不能只导入任何旧的二进制文件。 In addition the filesystem is read only, you couldn't write to sqlite db.
另外文件系统是只读的,你不能写入sqlite db。
You mention this is a fresh install of OSX. 你提到这是OSX的全新安装。 I wonder if you used Homebrew to build Python?
我想知道你是否使用Homebrew来构建Python? Doing Brew-update or brew-upgrade caused me similar problems to this, although not on GAE.
做Brew-update或brew-upgrade会给我带来类似的问题,尽管不是GAE。 You might find https://github.com/mxcl/homebrew/issues/17312 useful.
您可能会发现https://github.com/mxcl/homebrew/issues/17312非常有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.