No module named '__main__.demo'; '__main__' is not a package python3

前端 未结 1 1114
春和景丽
春和景丽 2021-01-05 13:59

If I execute main.py it works fine, the problem is when I execute demo2.py

|myPackage
   |subPackage
      demo.py
      demo2.py
          


        
相关标签:
1条回答
  • 2021-01-05 14:24

    If you drop the ., it should work. demo2.py becomes:

    from demo import demoprint # instead of `from .demo import demoprint`
    
    def demo2_print():
        print("demo2")
        demoprint()
    
    demo2_print()
    

    Now you can run %run ludikDriver/demo2.py in ipython for instance and you get:

    demo2
    demo
    

    For more details, the section "Imports" of this article might help.

    0 讨论(0)
提交回复
热议问题