2012-02-20 114 views
9

我的目錄結構是這樣的:沒有模塊的App Engine App Engine中

project 
    app.yaml 
    main.py 
    lib 
     markdown 
     markdown_files 

降價在main.py被導入由from lib.markdown import markdown。此時,dev服務器開始給我下面的堆棧跟蹤。我想知道這裏有什麼問題!?我在lib中有一個init .py。

Traceback (most recent call last): 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 2769, in _HandleRequest 
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 2654, in _Dispatch 
    base_env_dict=env_dict) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 683, in Dispatch 
    base_env_dict=base_env_dict) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 1718, in Dispatch 
    self._module_dict) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 1622, in ExecuteCGI 
    reset_modules = exec_script(config, handler_path, cgi_path, hook) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 1310, in ExecuteOrImportScript 
    exec module_code in script_module.__dict__ 
    File "/Users/nomadali/jeeqs/git/src/jeeqs.py", line 26, in <module> 
    from lib.markdown import markdown 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate 
    return func(self, *args, **kwargs) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1845, in load_module 
    return self.FindAndLoadModule(submodule, fullname, search_path) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate 
    return func(self, *args, **kwargs) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1717, in FindAndLoadModule 
    description) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate 
    return func(self, *args, **kwargs) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1660, in LoadModuleRestricted 
    description) 
    File "/Users/nomadali/jeeqs/git/src/lib/markdown/__init__.py", line 161, in <module> 
    import preprocessors 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate 
    return func(self, *args, **kwargs) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1845, in load_module 
    return self.FindAndLoadModule(submodule, fullname, search_path) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate 
    return func(self, *args, **kwargs) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1717, in FindAndLoadModule 
    description) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate 
    return func(self, *args, **kwargs) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1660, in LoadModuleRestricted 
    description) 
    File "/Users/nomadali/jeeqs/git/src/markdown/preprocessors.py", line 11, in <module> 
ImportError: No module named markdown 
INFO  2012-02-20 19:53:02,506 dev_appserver.py:2884] "GET /favicon.ico HTTP/1.0" 500 - 

UPDATE1

我相信這個問題是Import Python module with PyImport_ImportModuleEx for a gedit plugin

答案愚弄的人:

如果你想使用降價,而無需修改它,然後你會必須把它放在Python庫期望的地方,比如在site-packages /裏。否則,您將不得不修改它以使用相對導入而不是絕對導入。

sys.path.append(os.path.join(os.path.dirname(文件

更新2 我修改我的應用程序引擎的sys.path解決這個問題),「LIB」))

感謝穆拉特的幫助,

+0

除非你有很多第三方模塊,否則刪除lib目錄並將markdown目錄放到項目的根目錄會更簡單。那麼你根本不需要編輯你的路徑。 – 2012-02-28 13:57:03

+0

我確實有很多庫。 – Ali 2012-03-02 19:17:33

+0

你應該添加你的答案作爲你的問題的答案,並將你的答案標記爲正確的答案。謝謝。 – amirouche 2012-09-26 15:24:27

回答

0

我相信這個問題是導入Python模塊與PyImport_ImportModuleEx一個欺騙了的gedit插件

答案:

如果你想使用降價,而無需修改它,然後你將不得不把它在Python庫期望的地方,比如在site-packages /中。否則,您將不得不修改它以使用相對導入而不是絕對導入。

更新2我在應用程序引擎修改我的sys.path解決這個問題:

sys.path.append(os.path.join(os.path.dirname(文件), 'LIB'))

感謝穆拉特的幫助,

-1

你想要的是LIB在你的PYTHONPATH,這裏的Python看起來東西,你嘗試導入的路徑。正如你發現的,一種方法是將lib添加到sys.path中。

創建一個init .py文件不是你想要的,因爲這使得lib成爲一個包含markdown的包。在這一點上,你應該可以做

from lib import markdown 

雖然這不是推薦的方法。

0

該文件需要被稱爲__init__.py該工作。

將lib目錄添加到pythonpath也可以。

如果你想使用降價,而無需修改它,然後你將不得不把它的地方,其中Python庫期望它,比如在站點包/

這是不正確,應用程序引擎有其自己的導入機制,只有明確列入白名單的包才允許通過此方法導入。