skytreader skytreader - 1 year ago 64
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?

Answer Source

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

python -m pkg.tests.core_test
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download