1

I'm getting "Attempted relative import in non-package" in this import statement. Where is the issue?

from ..Resources.UniversalHelper.Helper import UniversalPageHelper

Structure:

project/
        __init__.py
        MainFiles/
                  __init__.py
                  Main.py (where this from statement is being called)
        Resources/
                 __init__.py
                 UniversalHelper/
                                 __init__.py
                                 Helper.py
William Falcon
  • 9,813
  • 14
  • 67
  • 110

1 Answers1

4

It doesn't really matter that you've put __init__.py files in every directory. It seems to me, that importing Main.py is done by import Main somewhere or by running the scriptpython project/MainFiles/Main.py.

ValueError: Attempted relative import in non-package tells you, that Main is not loaded as part of a package structure. You need to import it as complete package like import project.MainFiles.Main or run it as module python -m project.MainFiles.Main.

If the last is your problem, you should also have a look into __main__.py.

tynn
  • 38,113
  • 8
  • 108
  • 143
  • yes, anytime you are running a main program deep in a project, you should be using `python -m` – rbp Feb 01 '15 at 16:17