0

I want to import an object from a module in a package inside another module of a sibling package. But the parent directory has the same name as one of the packages.

Here is the structure I am struggling with:

foo{
  __init__.py
  foo{
    __init__.py
    models.py
  }
  bar{
    __init__.py
    models.py
  }
}

Inside of foo (not the parent) I want to import an object from bar.models.

I tried this:

from foo.bar.models import MyObject

and

from ..bar.models import MyObject

None worked, how do you do ?

Mike Delta
  • 726
  • 2
  • 16
  • 32
  • Does this answer your question? [Sibling package imports](https://stackoverflow.com/questions/6323860/sibling-package-imports) – Chase Nov 11 '20 at 13:52

1 Answers1

0

To import from another sibling directory, it's more efficient to use the sys module and the path:

import sys
sys.path.append('../bar')
import models
# ...