繁体   English   中英

Python:我自己的模块的ImportError

[英]Python: ImportError of my own module

Error: ImportError: No module named common_components.modules.logging.logger运行python emailsender.py时, Error: ImportError: No module named common_components.modules.logging.logger发生Error: ImportError: No module named common_components.modules.logging.logger

输出:

(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

任何想法? 谢谢

UPDATE

(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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM