Description of the issue
When using PyInstaller to bundle submodules of a namespace package, where each submodule is its own module (see the example at PyPA, none of the submodules appear under the namespace when iterating over the namespace using pkgutil.iter_modules. Using from namespace import submodule does work, however.
Printing the namespace module after importing it in a script and from an exe shows two different results:
import namespace
print(namespace)
# Script output: <module 'subpackages' (namespace)>
# PyInstaller output: <module 'namespace' from 'path_to_namespace/__init__.pyc'>
In addition, for the code example linked below, when I ran PyInstaller with --debug all and looked in dist/pyi_ns_issue/subpackages, only submod_b (which is explicitly imported unlike submod_a) is listed.
Context information (for bug reports)
-
Output of pyinstaller --version: 4.0
-
Version of Python: e.g. 3.7.5 and 3.8.2
-
Platform: Ubuntu 20.04.1 LTS
-
Did you also try this on another platform? Does it work there? Encountered the same issue on Windows 10 Enterprise 1809
-
try the latest development version, using the following command:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
A minimal example program which shows the error
I've made a repo with a mimimal example at: https://github.com/SpenserHaddad/pyinstaller-namespace-issue-repro
Here's the offending code from the repo:
impl_modules = pkgutil.iter_modules(subpackages.__path__, subpackages.__name__ + ".")
# impl_modules is an "empty" generator, and the nothing will happen in the loop below
for mod in impl_modules:
loaded_mod = importlib.import_module(mod.name)
print(loaded_mod.sayhi())
Stacktrace / full error message
Please also see https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs
for more about what would use to solve the issue.
Description of the issue
When using PyInstaller to bundle submodules of a namespace package, where each submodule is its own module (see the example at PyPA, none of the submodules appear under the namespace when iterating over the namespace using
pkgutil.iter_modules. Usingfrom namespace import submoduledoes work, however.Printing the namespace module after importing it in a script and from an exe shows two different results:
In addition, for the code example linked below, when I ran PyInstaller with
--debug alland looked indist/pyi_ns_issue/subpackages, onlysubmod_b(which is explicitly imported unlikesubmod_a) is listed.Context information (for bug reports)
Output of
pyinstaller --version:4.0Version of Python: e.g. 3.7.5 and 3.8.2
Platform: Ubuntu 20.04.1 LTS
Did you also try this on another platform? Does it work there? Encountered the same issue on Windows 10 Enterprise 1809
try the latest development version, using the following command:
(https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong) and
Make sure everything is packaged correctly
--noupxor setupx=Falsein your .spec-file--debugtopyi-makespecorpyinstalleror useEXE(..., debug=1, ...)in your .spec file.A minimal example program which shows the error
I've made a repo with a mimimal example at: https://github.com/SpenserHaddad/pyinstaller-namespace-issue-repro
Here's the offending code from the repo:
Stacktrace / full error message
Please also see https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs
for more about what would use to solve the issue.