0

I have been using the following relative approach to importing items:

from .utils import *

However, it doesn't seem to be working consistently, and I will often get the following error on both python3.6 and python3.7 (on both mac and ubuntu):

from .utils import *

ImportError: attempted relative import with no known parent package

The hack fix I have implemented is as follows:

try:
    from .utils import *
except ImportError:
    from utils import *

But this seems like the worst approach of all. Why does this error sometimes occur, and what would be the best approach to fix it?

David542
  • 104,438
  • 178
  • 489
  • 842
  • 1
    What is the directory structure ? – ravikt Dec 04 '19 at 07:03
  • Does this answer your question? [Relative imports in Python 3](https://stackoverflow.com/questions/16981921/relative-imports-in-python-3) – AMC Feb 08 '20 at 02:07

0 Answers0