flask/werkzeug hooks

294 views
Skip to first unread message

Wolf-Dietrich Seidlitz

unread,
Aug 13, 2011, 4:44:45 PM8/13/11
to pyins...@googlegroups.com
After some years of django usage i developed my last project using flask/werkzeug. This lead to a problem i haven't thought of in the beginning. The application cannot be distributed with the help of pyinstaller. Flask/Werkzeug is doing some "lazy" imports, which is not recognized by pyinstaller without additional help by the hooks package. The simple way naming the modules in the global hiddenimports array is not enough. The error i see when running the created exe:

File "d:\download\pyinstaller-1.5.1\iu.py", line 436, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "d:\download\pyinstaller-1.5.1\iu.py", line 521, in doimport
exec co in mod.__dict__
 File "c:\users\tds\workspace\flask\tds_flask\build\pyi.win32\runserver\outPYZ1.pyz/flask", line 17, in <module>
 File "c:\users\tds\workspace\flask\tds_flask\build\pyi.win32\runserver\outPYZ1.pyz/werkzeug", line 119, in __getattr__
File "d:\download\pyinstaller-1.5.1\iu.py", line 454, in importHook
del sys.modules[fqname]
KeyError: 'werkzeug.exceptions'

A more complex hooks scenario is necessary, to solve this problem. But this is beyond my knowledge, not only because the documentation is minimal.

Is there someone with helpful hints for me?

TIA,
Wolf

Wolf-Dietrich Seidlitz

unread,
Aug 15, 2011, 2:37:15 AM8/15/11
to pyins...@googlegroups.com
Problem solved by eliminating all deferred imports from flask/werkzeug (This is only true for building the executable without debug mode, which is okay for a deployable application)

Carsten Grohmann

unread,
Aug 15, 2011, 3:46:38 PM8/15/11
to pyins...@googlegroups.com
Hi Wolf,

Am Samstag, 13. August 2011 schrieb Wolf-Dietrich Seidlitz:
> The simple way naming the modules in the global *hiddenimports* array is
> not enough. The error i see when running the created *exe:*

Do you really change the global hiddenimports array in the spec file?
How did you do it?

Regards,
Carsten

Hartmut Goebel

unread,
Aug 16, 2011, 2:47:07 AM8/16/11
to pyins...@googlegroups.com
Am 15.08.2011 21:46, schrieb Carsten Grohmann:
> Do you really change the global hiddenimports array in the spec file?
> How did you do it?
You should not change it, even if it's possible, it's not part of the API.

--
Schönen Gruß - Regards
Hartmut Goebel
Dipl.-Informatiker (univ.), CISSP, CSSLP

Goebel Consult
Spezialist für IT-Sicherheit in komplexen Umgebungen
http://www.goebel-consult.de

Monatliche Kolumne: http://www.cissp-gefluester.de/
Goebel Consult mit Mitglied bei http://www.7-it.de


Carsten Grohmann

unread,
Aug 16, 2011, 12:26:44 PM8/16/11
to pyins...@googlegroups.com
Am Dienstag, 16. August 2011 schrieb Hartmut Goebel:
> Am 15.08.2011 21:46, schrieb Carsten Grohmann:
> > Do you really change the global hiddenimports array in the spec file?
> > How did you do it?
>
> You should not change it, even if it's possible, it's not part of the API.

May it makes sense to create an enhancement request for this topic?

Regards,
Carsten

Hartmut Goebel

unread,
Aug 16, 2011, 3:12:37 PM8/16/11
to pyins...@googlegroups.com
Am 16.08.2011 18:26, schrieb Carsten Grohmann:
> May it makes sense to create an enhancement request for this topic?
Well, there are already:

a) There is already a way to implement hidden imports as documented in
<http://www.pyinstaller.org/export/latest/tags/1.5.1/doc/Manual.html?format=raw#listing-hidden-imports>

b) There is already an enhancement request "add cli option to specify
custom hooks folder" <http://www.pyinstaller.org/ticket/325>

I personally prefer hooks over one-shot-stuff. But I admit there may be
cases, where a hook is overdone. So if you are preparing a patch, we'll
surely implement it.

Reply all
Reply to author
Forward
0 new messages