2017-01-09 16 views
0

日午前beetwenモジュール&コアを認識していけない:私のプログラムは、私は、私は次のエラーを取得するPythonのプログラムを持って、私はpython2

ImportError: No module named core

エラーの原因インポートは、次のとおりです。

from core import wcolors 

ファイルwcolors.pycoreという名前のディレクトリにあり、モジュールと呼ばれる別のディレクトリがあるので、私のプログラムを実行すると、このエラー出力が出ます:

ディレクトリ構造

ディレクトリ構造は、コア内のすべてのファイルは、.pycファイル拡張子を使用してコンパイルされている別の詳細としてその

anubis 
--anubis.py (the script that i run) 
--core 
    --wcolors.py (the file i import from core) 

-- modules 
    [the modules i suposed to load during the execution.] 

ように続きます。

答えて

1

anubisanubis/coreディレクトリにブランク__init__.pyを追加するだけで済みます。これはうまくいくはずです。 __init__.pyファイルがない場合、pythonはそのディレクトリがモジュールであるとは考えません。

The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file

Python docs

0

あなたはこの試みることができます:

from anubis.core import wcolors 

をしたり、 "コア" の名前を変更することができ、それはジャンゴとPythonのキーワードである可能性があります。

+0

ありがとうございます!できます! – dashboy

関連する問題