0

Assume I have the following structure of a package:

parent/
  package/
    __init__.py
    utils/
      __init__.py
      foo.py
    apps/
      __init__.py
      bar.py

Now, I want to import the module foo from the module bar. What is the correct way to do it? I will welcome comments on the structure of my project :)

So far I only found answers where everything lives in the same directory... I tried something like:

from ..utils import foo

but I get:

Traceback (most recent call last):
  File "./bar.py", line 4, in <module>
    from ..utils import foo
ValueError: Attempted relative import in non-package
Dror
  • 12,174
  • 21
  • 90
  • 160
  • Might be a duplicate: http://stackoverflow.com/questions/11536764/attempted-relative-import-in-non-package-even-with-init-py I'm still checking... – Dror Aug 27 '14 at 10:24

1 Answers1

0

I think, it's better to set some environ variable or extend PYTHONPATH (it must be done in main script)

Sergius
  • 908
  • 8
  • 20