I've been reading tons of questions related to this matter but none of the has help me so far. I'm currently using the Python click
library to execute scripts as commands.
The current command that I'm trying to execute is placed inside a Python Package which has a __main__.py
file, like the parent dir has. The current project structure is the following one.
/myproject
/foo_one
__init__.py
foo_one.py
/foo_two
__init__.py
foo_two.py
/foo_three
__init__.py
foo_three.py
/foo_four
__init__.py
foo_four.py
/foo_five
__init__.py
foo_five.py
/foo_six
__init__.py
foo_six.py
__init__.py
__main__.py
foo_seven.py
Whenever I try to run the __main__.py
script located in the project folder, the following error comes up.
ModuleNotFoundError: No module named '__main__.foo_two'; '__main__' is not a package
However, if I try to execute that same script from a folder above with the -m
option like this python3 myproject -m
, the following is shown up.
ImportError: attempted relative import with no known parent package
The __main__.py
has 2 imports like this... The __init__.py
is empty.
from .foo_two.foo_two import AClass, AnotherClass, OtherClass
from .foo_three.foo_three import AnotherClassMore
UPDATE: Correcting the syntax error in a previous command, while calling python -m myproject
gives me a ModuleNotFoundError
because of a module that isn't my responsibility, which is basically a library that is used in the project.