Error: ImportError: No module named common_components.modules.logging.logger
運行時發生python emailsender.py
。Python:導入錯誤我自己的模塊
輸出:
(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
'common_components'是不是在你的Python路徑。解決這個問題最簡單的方法就是用''common_components/modules/email/emailsender.py''來運行你的腳本。工作目錄總是在python路徑中。 –
你的'python'目錄裏有'__init __。py'。不知道這是否有所作爲,但它確實看起來很奇怪,因爲我認爲你不打算成爲一個包裝。 –