2013-05-26 77 views
4

更新:這是我在1.8.0 App Engine SDK上全新安裝的OS X 10.8.3上遇到的問題。OS X AppEngine - ImportError:沒有名爲_sqlite3的模塊

首先 - 有一堆關於SO的問題與相似的標題。我檢查了他們,我不相信他們回答我的問題。他們大多建議得到libsqlite3-dev的和重建蟒蛇得到_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 

實際的代碼,導致應用程序引擎SDK,以嘗試加載模塊:


remaining = TaskSetElement.all().filter('taskSet', ts_key).filter('complete', False).count() 

這裏的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 

我有一大堆的數據存儲代碼之前。我直接從命令行運行dev_appserver.py或在pydev運行eclipse時遇到了同樣的問題。

在命令行中,一切看起來不錯:

 
$ 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'] 
>>> 

這段代碼(在應用程序引擎SDK運行),將刪除方程式App Engine數據存儲代碼:


... 
logging.info("Python Version: %s" % sys.version) 
logging.info(filter(lambda p: 'lib-dynload' in p, sys.path)) 

import sqlite3 
... 
 

它輸出這:

 
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 

任何想法是什麼問題?謝謝,

科林

回答

8

它看起來像在sandbox.py線742(其在/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python我的機器上住)加入'_sqlite3'_WHITE_LIST_C_MODULES列表很適合我現在。

對我沒有受過教育的眼睛來說,它看起來像CModuleImportHook不正確地阻止_sqlite3的導入,並且修改它必須返回的任何一項檢查None可以清除錯誤。有更多的人 - 請擴展我所說的話或糾正我!

該更改可能允許您在自己的代碼中導入_sqlite3,這將是一個錯誤。也許它需要一種方法來限制導入到dbapi2.py?

+0

完美!我正在運行通過eclipse實際運行linux GAE SDK發行版,但該解決方案在那裏也很好 - 謝謝你的幫助,非常感謝。 – hawkett

+0

很高興幫助。這個問題一直在困擾我很多年! – personalnadir

1

從你的堆棧跟蹤它表明你正試圖在你的main.py.導入源碼

你爲什麼這樣做?

在appengine中不支持導入sqlite。 sqlite是用二進制庫實現的,你不能只導入任何舊的二進制文件。另外文件系統是隻讀的,你不能寫入sqlite數據庫。

+1

據我瞭解,本地開發服務器中的數據存儲是使用SQLite實現的,因此導入發生在App Engine代碼中,而不是他自己的(請參閱問題中的最後一個代碼片段)。 – omz

+0

正確 - 應用程序引擎在sdk中導入sqlite以支持開發數據存儲 - 這是我在開發環境中遇到的問題。在我自己的代碼中導入只是爲了演示問題(它不是用於生產部署),打印python版本並顯示路徑包含它在我的運行時環境中應該包含的內容。我的測試代碼是在第一次查看應用程序引擎代碼之後構建的,即我正在導入相同的東西來生成相同的錯誤。 – hawkett

+0

我已經修改了這個問題,首先把SDK問題,包括應用程序引擎的堆棧跟蹤,以及我的演示代碼。我發現此問題可能與以下問題有關:https://code.google.com/p/googleappengine/issues/detail?id=9008 - 針對同一問題在3月26日和4月27日發表的評論。 – hawkett

相關問題