0

I'm trying to use a piece of code I got from somewhere. The code has a structure equivalent to this:

project/
   test.py
   somepackage/
      __init__.py
      file1.py
      file2.py

__init__.py contains only:

from file1 import *
from file2 import *

while in test.py I have

from somepackage import *

Running test.py gives an error:

AttributeError: module 'somepackage' has no attribute 'file1'

I'm using python version 3.5 if that matters

  • 2
    Use a relative import: `from .file import *` – Jonathon Reinhart Dec 28 '17 at 16:04
  • Also see [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time). – martineau Dec 28 '17 at 16:22
  • Thanks, it works! I'm a bit puzzled, though, by the fact that this was a piece of code made by someone else available on github. I would think that the person has at least tested that the imports in the code work. – user9149928 Dec 29 '17 at 09:36

0 Answers0