skytreader skytreader - 8 months ago 27
Python Question

How to fix "Attempted relative import in non-package" even with

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


I have the following import statement

from ..components.core import GameLoopEvents

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

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

Searching around I found "relative path not working even with" and "Import a module from a relative path" but they didn't help.

Is there anything I'm missing here?


Yes. You're not using it as a package.

python -m pkg.tests.core_test