pythonnamespacespackagepyinstallernamespace-package

pyinstaller with namespace packages


I have a module/package structure where I am using namespace packages, I have multiple user made libraries which I keep in separate repositories, and they have fairly generic names like db, io, utils and so on. To avoid conflict with other packages I have a top level/namespace package named acme, i.e. my packages are acme.io, acme.db, acme.utils and so on. To make this work, the __init__.py in all the acme folders has the following lines

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

This works well when running the software which uses these packages from python.

But then I try making an EXE using pyinstaller. pyinstaller finds only one of these packages. I tried to set the pathex to the folder where each of these libraries reside:

a = Analysis(['.\\src\\myPgogram.py'],
         pathex=['C:\\Data\\python\\myProgram', 'C:\\Data\python\\dbrepo', 'C:\\Data\\python\\utilsrepo', 'C:\\Data\\python\\iorepo'],
         hiddenimports=['acme', 'acme.io', 'acme.utils', 'acme.db'],
         hookspath=None,
         runtime_hooks=None)

In the folders dbrepo, iorepo and utilsrepo there is a folder named acme, with the above mentioned __init__.py file and the the corresponding package, i.e. db, utils and io, with a __init__.py file within them again.

But pyinstaller only finds the acme and acme.db package. Or it finds only the package which path is listed first in the pathex variable.

Any hints to how I can make this work?

Thanks


Solution

  • Namespace packages are not supported in Pyinstaller 2.1, it will be supported in later versions.

    The solution I use is that in my build script I copy the libs to a common acme folder, temporarily, and add this path to the pathex in Analysis. On *nix systems one can create symlinks instead of copying the repos. Thanks to Hartmut Goebel of the Pyinstaller team for clearifying the issue.