The simplest way to organise your package is like this:
Of course you can have more than one sub-module or sub-package.
Technically it is not absolutely necessary to have an
file in the package, but the rules for skipping it are very complicated
and most people (including me!) don’t understand it. So save yourself a
lot of pain and always include
__init__.py, even if it is an empty
__main__.py file is used when you run the package as if it were a
# Don't do this!
# Do this instead:
python3 -m mypackage
# or if you have to specify the full path:
That will automatically treat the package as a script and run the code
__main__.py file. That keeps it nicely independent from the
code that gets run when you import the package:
import mypackage # uses mypackage/__init__.py
Of course you can import code inside
__main__.py like this:
from . import stuff
Try reorganising your package to put the script-like code in a seperate
__main__.py file and see if that helps.