'How to import from __init__ file of a packge

I have very sample structure like this

main.ipynb
package1
   __init__.py
   class1.py
  • class1.py
class Class1():
    def __init__(self) -> None:
        print("Class1")
        pass

  • __init__.py
from class1 import Class1

It's raise an error ImportError: cannot import name 'Class1' from 'package1'

I'm using Python 3.7.11, Ubuntu. I try to from .class1 import Class1 but it now work. How to solve that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source