Thank you for the prompt response. I agree with your explanation, but would like to avoid having to manually import submodules in every package's __init__.py if possible. I will if I must, but this was a toy example - the code base I'd like to bundle is far more complex and, up to now, everything has worked without hand-crafted imports.
If possible, I'd like to resolve it using PyInstaller's functionality. Specifically, I was under the impression that using --hidden-import (or, more likely, a custom hook) would solve the problem. Quoting the PyInstaller docs (https://pyinstaller.readthedocs.io/en/stable/hooks.html): * Many hooks consist of only one statement, an assignment to hiddenimports. For example, the hook for the dnspython package, called hook-dns.rdata.py, has only this statement:* * hiddenimports = [* * "dns.rdtypes.*",* * "dns.rdtypes.ANY.*"* * ]* * When Analysis sees import dns.rdata or from dns import rdata it calls hook-dns.rdata.py and examines its value of hiddenimports. As a result, it is as if your source script also contained *[my emphasis]*:* * import dns.rdtypes.** * import dsn.rdtypes.ANY.** My question would then be: if I can solve it with "import mypkg.mymod" in my script, why can't I solve it with "--hidden-import=mypkg.mymod" in PyInstaller? Thanks again. I do appreciate you taking the time to help me understand. On Friday, 2 October 2020 at 4:37:33 pm UTC+1 bwoodsend wrote: > That setup should fail even without PyInstaller because mypkg.mymod is > never imported. > > # This initialises mypkg.__init__ only. > > > import mypkg > if __name__ == "__main__" > > : > # So even if mymod has been collected by PyInstaller, it won't have been > loaded > # and set as an attribute of `mypkg`. > mypkg.mymod.myfunc() > > Possibly what your after is the following line in __init__.py? > > from . import mymod > > That way, initialising mypkg (using import mypkg) will implicitly load > mymod and you can safely use mypkg.mymod.myfunc(). Alternatively you can > just import mypkg.mymod. > -- You received this message because you are subscribed to the Google Groups "PyInstaller" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/d6b71bdb-e47b-4c02-a39e-039cf4781baen%40googlegroups.com.
