文件目录结构:
test/
__init__.py
example1.py
demo/
__init__.py
example2.py
demo文件夹下的exampl2.py文件引用上级目录里的模块报错:
from .example1 import *
~/test/test$ python test_example2.py
Traceback (most recent call last):
File "test_example1.py", line 1, in <module>
from example1 import *
ImportError: No module named example1
快速解决方法:在引入包的最外层目录新建main.py文件调用需要执行的文件
main.py:
from test.demo import example2