Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

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

Asked by Anusha Acharya Jun 1, 2021 1.5K views 1 answer
Share

About this question

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

pkg/
   __init__.py 
   components/ 
      Core.py
      __init__.py 
   tests/ 
     Core_test.py
     __init__.py

In core_test.py I have the following import statement

from ..components.core import GameLoopEvents

However, when I run, I get the following error:

tests$ python core_test.py
 Traceback (most recent call last):
   File "core_test.py", line 3, in  
     from ..components.core import GameLoopEvents 
 ValueError:   Attempted relative import in non-package

Is there anything I'm missing here?

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.