2

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

shuttle87
  • 15,466
  • 11
  • 77
  • 106
thorsan
  • 1,034
  • 8
  • 19

2 Answers2

0

I just had the same issue. Looked up this: http://pythonhosted.org/PyInstaller/#extending-the-path and added some --paths to my build batch file call.

which is something like:

@echo off
echo ========= %~n0 =========

set pyfile=scriptName.py
set pypath=C:\Python27\Scripts
set buildpath=%temp%
set distpath=%~dp0

%pypath%\pyinstaller.exe --onefile -y %~dp0%pyfile% --distpath=%distpath% --workpath=%buildpath% --specpath=%buildpath% --noupx --paths=D:\Tools\dev\python --paths=D:\somepath

cheers!

ewerybody
  • 1,443
  • 16
  • 29
  • I have added the path of the different locations where the acme sub packages are located: --paths=C:\Data\python\dbrepo --paths=C:\Data\python\utilsrepo but it only recognizes the acme and acme.db package, not the acme.utils package in the second path – thorsan May 28 '15 at 13:14
  • weird. changing the order has the same result? And putting it not to the Analysis object but to annother collector? with this TOC Class? – ewerybody May 29 '15 at 13:50
  • Another collector? Could you please elaborate? TOC class? I see that the get_pacakge_paths method in hookutils only gives the first path of the package, not all of them, so collect_submodules() will only give submodules for the first path of the package. – thorsan May 31 '15 at 05:50
  • So there is actually a bug in pyinstaller? .. What I meant is: Maybe You can instead of putting it to the "analysis" object just add the libraries you intend to have in your package with the "EXE" collector (If you're going for the one file option). I was just adding image files this way and probably you can do the same with script files http://pythonhosted.org/PyInstaller/#toc-class-table-of-contents – ewerybody Jun 01 '15 at 09:49
  • Namespace pacakges are not supported in Pyinstaller 2.1, its scheduled for version 3.0. https://groups.google.com/forum/#!topic/pyinstaller/FcZa03oPzhY https://github.com/pyinstaller/pyinstaller/issues/502 – thorsan Jun 01 '15 at 11:48
  • Are you using namespace packages? – thorsan Jun 02 '15 at 05:31
0

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.

thorsan
  • 1,034
  • 8
  • 19