What follows below is just elaborating on jonrsharpe's great comment that I think answers the question.
Python's from package import *
indeed looks deceptively like it imports everything from said package, but this is not the case. The docs say:
The import statement uses the following convention: if a package’s
__init__.py
code defines a list named __all__
, it is taken to be the list of module names that should be imported when from package import
* is encountered.
So if there is an __init__.py
file in the package directory (it has to, otherwise it's not gonna be imported anyway) and it contains a list named __all__
than this list's contents are treated as module names to be imported into the calling module's namespace.
What happens if __all__
variable is not defined in __init__.py
? Paraphrasing a further paragraph from the docs:
If __all__
is not defined, the statement from package import *
does not import all submodules from the package into the
current namespace; it only ensures that the package has
been imported (possibly running any initialization code in
__init__.py
) and then imports whatever names are defined in the package. This includes any names defined (and submodules explicitly
loaded) by __init__.py
. It also includes any submodules of the package
that were explicitly loaded by previous import statements.
If you want a good example where understanding this is crucial, head over to video #20 introducing GUI programming with TkInter in Derek Banas's excellent Python YT series.