pyinstaller cannot locate ExcelModel class in excel\__init__.py file of formulas package

45 views
Skip to first unread message

Widdershins

unread,
Jul 9, 2020, 3:27:39 AM7/9/20
to PyInstaller
I'm trying to build a Windows exe using pyinstaller (my second time) and I'm using the formulas package from PYPI.

I'm using a class ExcelModel from formulas. I can import this successfully into VSCode and run it no problem using a variety of import statements, including the simplest: import formulas
However, pyinstaller cannot locate this ExcelModel class.
After a lot of fiddling using pyinstaller diagnostics (Thanks!) I've come to the conclusion that the problems are:

1) The ExcelModel class is located in the formulas\excel\__init__.py file, rather than in, for instance, formulas\excel\ExcelModel.py.

2) With pyinstaller I've tried many --hidden-import expressions and a few alternative Python import statements and I cannot get pyinstaller to recognise that ExcelModel class exists anywhere, unless I use: "from formulas.excel.__init__ import ExcelModel"
This statement works in VSCode and also causes pyinstaller to find the __init__ module containing ExcelModel class. Yay!
However, the __init__ module uses relative paths in its import statements and these immediately fail because of the strange import statement that I've been forced to use to get pyinstaller to find the module containing ExcelModel.

So, what's my problem: Is this one bug or two?

I presume that the formulas structure is undesirable or incorrect and I will ask the author about that.

However, why can't pyinstaller find the ExcelModel class inside the __init__.py file when using a simple "import formulas" statement when VSCode's python environment can find it?
Is this a blind spot in pyinstaller?

Is there some incantation that I haven't tried which will address this problem? 
Surely this problem isn't unusual? Why would a naming structure issue make generation of an executable impossible when the code runs in an IDE?

Thanks in advance for your comments.

bwoodsend

unread,
Jul 9, 2020, 7:26:27 AM7/9/20
to PyInstaller

Hmm, that is pretty odd. It certainly doesn’t normally matter if classes are defined in __init__.pyfiles.

I’ve tried PyInstallering formulas and it’s working normally on my machine. Looking at the source code however there is some rather unconventional stuff happening in the top level init.py where it uses __getattr__() to load its submodules. Maybe could you try removing/commenting out the getattr() function and changing the if statement so that it’s always true (if True or sys.version_info[:2] < (3, 7) or os.environ.get('IMPORT_ALL') == 'True': would do it) in the formulas.__init__.py installed on your machine.

Other than that it looks pretty vanilla so I don’t see what else could be the issue.

Brénainn

Widdershins

unread,
Jul 10, 2020, 3:49:36 AM7/10/20
to PyInstaller
Thanks for the suggestion.
There was no change in pyinstaller results with your suggestion implemented while using any of the aforementioned import strategies.
(Your suggested change worked fine with VSCode.)

bwoodsend

unread,
Jul 10, 2020, 5:16:36 PM7/10/20
to PyInstaller
I can reproduce your error by installing `formulas<=0.2.0`. Are you using an old version of formulas?

Widdershins

unread,
Jul 15, 2020, 7:03:25 AM7/15/20
to PyInstaller
Thanks for the suggestion, however I'm using formulas 1.0.0 and have only ever had that version installed.

The formulas author suggested I use a hook file and that has done the trick:

from PyInstaller.utils.hooks import collect_all


datas, binaries, hiddenimports = collect_all('formulas')


The pyinstaller xref info doesn't seem to have changed so I don't know what magic is going on behind the scenes.

Reply all
Reply to author
Forward
0 new messages