How to fix “Attempted relative import in non-package” even with __init__.py

后端 未结 19 2811
予麋鹿
予麋鹿 2020-11-21 21:51

I\'m trying to follow PEP 328, with the following directory structure:

pkg/
  __init__.py
  components/
    core.py
    __init__.py
  tests/
    core_test.py         


        
19条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 22:43

    In core_test.py, do the following:

    import sys
    sys.path.append('../components')
    from core import GameLoopEvents
    

提交回复
热议问题