2012-02-20 7 views
9

私のディレクトリ構造は、このようなものです:ないモジュールの名前値下げApp Engineはアプリエンジンで

project 
    app.yaml 
    main.py 
    lib 
     markdown 
     markdown_files 

値下げがfrom lib.markdown import markdownmain.pyにインポートされています。この時点で、devサーバは私に次のスタックトレースを与え始めています。私は何がここで間違っているのだろうと思っています!私は .pyをlibに持っています。

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 - 

アップデート1

私はこの質問には答え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ディレクトリを置くほうが簡単です。次にパスを編集する必要はありません。 –

+0

私は実際に多くのライブラリを持っています。 – Ali

+0

質問の回答として回答を追加し、回答を正しい回答としてマークしてください。どうも。 – amirouche

答えて

0

私はこの質問はgeditのプラグインのPyImport_ImportModuleExとインポートPythonモジュールのデュープであると考えてい

答え:

あなたが置く必要があるとしているし、それを修正せずに値下げを使用したい場合それはPythonライブラリが期待している場所(site-packages /など)です。それ以外の場合は、絶対インポートの代わりに相対インポートを使用するように変更する必要があります。

アップデート2私は、アプリエンジンで私のsys.pathを変更することによってこの問題を解決:

sys.path.append(os.path.join(os.path.dirname(ファイル)、 'LIB'))助けをミュラへ

おかげで、

-1

libには、あなたのPYTHONPATHにするために何が欲しいのは、あなたがインポートしようPythonがものに見えるのパスです。あなたが発見したように、これを行う1つの方法は、libをsys.pathに追加することです。

.pyファイルを作成すると、libにmarkdownを含むパッケージが作成されます。その時点で、あなたはできるはずです

from lib import markdown 

これは推奨された方法ではありませんが、それはできるはずです。

0

ファイルは仕事にそのための__init__.pyを呼び出す必要があります。

libディレクトリをpythonpathに追加することもできます。

あなたは、このようなサイトのパッケージのように、あなたはPythonライブラリがそれを期待しどこどこかでそれを置くために必要があるとしているし、それを修正せずに値下げを使用したい場合は/

これは間違っています、 appエンジンには独自のインポートメカニズムがあり、このメソッドを使用して明示的にホワイトリストされているパッケージのみをインポートすることができます。

関連する問題