Error: ImportError: No module named common_components.modules.logging.logger
时会发生 python emailsender.py
。
输出:
(dev) me@xxx:~/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) me@xxx:~/workspace/python/python$ tree
.
├── common_components
│ ├── __init__.py
│ ├── modules
│ │ ├── email
│ │ │ ├── emailsender.py
│ │ │ └── __init__.py
│ │ ├── __init__.py
│ │ ├── logging
│ │ │ ├── __init__.py
│ │ │ └── logger.py
└── __init__.py
有什么想法吗?感谢
更新
(dev) me@xxx:~/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) me@xxx:~/workspace/python$ cd python/
(dev) me@xxx:~/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
答案 0 :(得分:0)
Python将当前目录添加到PYTHONPATH
,但您当前的目录是~/workspace/python/python/common_components/modules/email
。
通过从~/workspace/python/python/
:
me@xxx:~/workspace/python/python$ python common_components/modules/email/emailsender.py
或手动设置PYTHONPATH
:
me@xxx:~/$ set PYTHONPATH=~/workspace/python/python/
me@xxx:~/workspace/python/python/common_components/modules/email$ python emailsender.py