2017-04-19 10 views
0

Error: ImportError: No module named common_components.modules.logging.loggerpython emailsender.pyの実行時に発生します。Python:自分のモジュールのImportError

出力:

(dev) [email protected]:~/workspace/python/python/common_components/modules/email$ python emailsender.py 
Traceback (most recent call last): 
    File "emailsender.py", line 23, in <module> 
    from common_components.modules.logging.logger import Log 
ImportError: No module named common_components.modules.logging.logger 

わからないかどうか、次のプロジェクト構造と間違って何か:

(dev) [email protected]:~/workspace/python/python$ tree 
. 
├── common_components 
│   ├── __init__.py 
│   ├── modules 
│   │   ├── email 
│   │   │   ├── emailsender.py 
│   │   │   └── __init__.py 
│   │   ├── __init__.py 
│   │   ├── logging 
│   │   │   ├── __init__.py 
│   │   │   └── logger.py 
└── __init__.py 

任意のアイデア?おかげ

UPDATE

(dev) [email protected]:~/workspace/python$ python python/common_components/modules/email/emailsender.py 
Traceback (most recent call last): 
    File "python/common_components/modules/email/emailsender.py", line 23, in <module> 
    from common_components.modules.logging.logger import Log 
ImportError: No module named common_components.modules.logging.logger 
(dev) [email protected]:~/workspace/python$ cd python/ 
(dev) [email protected]:~/workspace/python/python$ python common_components/modules/email/emailsender.py 
Traceback (most recent call last): 
    File "common_components/modules/email/emailsender.py", line 23, in <module> 
    from common_components.modules.logging.logger import Log 
ImportError: No module named common_components.modules.logging.logger 
+1

'common_components'があなたのPythonパスではありません。これを解決する最も簡単な方法は、 '.'から' python common_components/modules/email/emailsender.py'でスクリプトを実行することです。作業ディレクトリは常にpythonパスにあります。 –

+0

あなたの 'python'ディレクトリに' __init __。py'があります。違いがあるかどうかは分かりませんが、あなたがパッケージであることを意図していないと想像するのは奇妙に思えます。 –

答えて

0

PythonはPYTHONPATH現在のディレクトリが追加されますが、あなたの現在のディレクトリが~/workspace/python/python/common_components/modules/emailです。

修正このどちらか~/workspace/python/python/から実行して:

[email protected]:~/workspace/python/python$ python common_components/modules/email/emailsender.py 

または手動でPYTHONPATHを設定することによって:

[email protected]:~/$ set PYTHONPATH=~/workspace/python/python/ 

[email protected]:~/workspace/python/python/common_components/modules/email$ python emailsender.py 
+0

ありがとうございます。しかし、働いていない。私の投稿が更新されました。ありがとう – BAE

+0

'workspace/python/python'ディレクトリから' common_components'パッケージを見つけるために実行する必要があります。あなたは 'common_components'ではなく、' python'ディレクトリを持つ 'workspace/python'から実行しています。 –

+0

試しました。働いていない。有線。 – BAE

関連する問題