美文网首页
Python3 ImportError问题快速解决方案

Python3 ImportError问题快速解决方案

作者: 火柴菌 | 来源:发表于2017-11-22 13:47 被阅读0次

文件目录结构:

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 

相关文章

网友评论

      本文标题:Python3 ImportError问题快速解决方案

      本文链接:https://www.haomeiwen.com/subject/efvnvxtx.html