I have a python package with the following structure.
|-- Project
|-- package1
|-- package2
|-- __init__.py
|-- file1.py
|-- file2.py
|-- __init__.py
|-- cli.py
|-- setup.py
__init__.py under package2 contains the following:
# package2.__init__.py
from .file1 import func1
from .file2 import func2
__init.py under package1 is empty. cli.py contains the following import statement:
# package1.cli.py
from .package2 import func1, func2
Running cli as a console script after installing with setup.py runs successfully. However, running cli.py as a python file does not, and returns the error:
Traceback (most recent call last):
File "cli.py", line 6, in <module>
from .conversion import convert_rtpdump_to_video, convert_video_to_rtpdump
ImportError: attempted relative import with no known parent package
I'm not sure I understand when to use relative or absolute paths, and I don't understand why it works as a console script but not as a python file.