librelist archives

« back to archive

pyinstaller

pyinstaller

From:
Wolf-Dietrich Seidlitz
Date:
2011-08-14 @ 18:35
After years of deploying python apps using "pyinstaller", it's my first 
project with flask/werkzeug that will not run as a pyinstaller created 
'exe'.

The reasons are possibly the "lazy" imports in werkzeug - but i'm not 
sure. Adding the usual list of hidden imports to the pyinstaller's hooks 
package has no effect.

Is there anybody, with some helpful ideas. My knowledge of python is not 
deep enough, to solve this problem. After two days of guessing and testing
without success, the only solution I cab think of now, is the rewrite of 
the application using "django".

Any help will be appriciated

- Wolf

Re: [flask] pyinstaller

From:
Armin Ronacher
Date:
2011-08-14 @ 21:22
Hi,

On 8/14/11 8:35 PM, Wolf-Dietrich Seidlitz wrote:
> The reasons are possibly the "lazy" imports in werkzeug
If that is the case, just delete the __init__.py file and remove
everything from it.  Flask 0.7 does not depend on werkzeug's deferred
imports and imports from the actual modules.


Regards,
Armin

Re: [flask] pyinstaller

From:
Wolf-Dietrich Seidlitz
Date:
2011-08-15 @ 05:49
On Sun, 14 Aug 2011 23:22:25 +0200, Armin Ronacher 
<armin.ronacher@active-4.com> wrote:

> Hi,
>
> On 8/14/11 8:35 PM, Wolf-Dietrich Seidlitz wrote:
>> The reasons are possibly the "lazy" imports in werkzeug
> If that is the case, just delete the __init__.py file and remove
> everything from it.  Flask 0.7 does not depend on werkzeug's deferred
> imports and imports from the actual modules.
>
>
> Regards,
> Armin
>

Yes, my problem is gone. No, there are still dependencies from Flask
(Flask 0.7.2 py2.6) to the deferred imports of werkzeug.__init__.py,
for example 'abort', 'redirect', 'ImmutableDict', 'headers' to name a few.
I can change these imports in the flask modules to point to the actual
modules. Would you recommend this, or do you have a hint, how i can tell
pyinstaller about the deferred imports.

Regards,
Wolf

Re: [flask] pyinstaller

From:
Armin Ronacher
Date:
2011-08-15 @ 06:31
Hi,

On 8/15/11 7:49 AM, Wolf-Dietrich Seidlitz wrote:
> Yes, my problem is gone. No, there are still dependencies from Flask
> (Flask 0.7.2 py2.6) to the deferred imports of werkzeug.__init__.py,
> for example 'abort', 'redirect', 'ImmutableDict', 'headers' to name a few.
> I can change these imports in the flask modules to point to the actual
> modules. Would you recommend this, or do you have a hint, how i can tell
> pyinstaller about the deferred imports.
Seems like that change was only made in Flask 0.8 which is currently a
development version.  Either upgrade to that or change the imports by
hand :)


Regards,
Armin

Re: [flask] pyinstaller

From:
Simon Sapin
Date:
2011-08-15 @ 06:34
Le 15/08/2011 08:31, Armin Ronacher a écrit :
> Seems like that change was only made in Flask 0.8 which is currently a
> development version.  Either upgrade to that or change the imports by
> hand:)
>

If you don’t want to upgrade I’d advise to fork the 0.7-maintenance 
branch to maintain patches.

Regards,
-- 
Simon Sapin

Re: [flask] pyinstaller

From:
Wolf-Dietrich Seidlitz
Date:
2011-08-15 @ 08:15
Changed the imports by hand. Wasn't to much.

Now everything is perfect!

Thank you all,
Wolf

Re: [flask] pyinstaller

From:
Simon Sapin
Date:
2011-08-14 @ 19:01
Le 14/08/2011 20:35, Wolf-Dietrich Seidlitz a écrit :
> After years of deploying python apps using "pyinstaller", it's my first 
project with flask/werkzeug that will not run as a pyinstaller created 
'exe'.
>
> The reasons are possibly the "lazy" imports in werkzeug - but i'm not 
sure. Adding the usual list of hidden imports to the pyinstaller's hooks 
package has no effect.
>
> Is there anybody, with some helpful ideas. My knowledge of python is not
deep enough, to solve this problem. After two days of guessing and testing
without success, the only solution I cab think of now, is the rewrite of 
the application using "django".
>
> Any help will be appriciated
>
> - Wolf


Hi,

I’m not sure what the problem is but maybe with more information we can 
help.

What exactly does not work? What are the steps to get there? What are 
the expected and obtained behavior then? Do you can an error message or 
traceback? What does it say exactly?

Regards,
-- 
Simon Sapin

Re: [flask] pyinstaller

From:
Wolf-Dietrich Seidlitz
Date:
2011-08-14 @ 20:51
On Sun, 14 Aug 2011 21:01:58 +0200, Simon Sapin <simon.sapin@exyr.org> wrote:
>
>
> Hi,
>
> I’m not sure what the problem is but maybe with more information we can
> help.
>
> What exactly does not work? What are the steps to get there? What are
> the expected and obtained behavior then? Do you can an error message or
> traceback? What does it say exactly?
>
> Regards,

Merci pour la réponse vite.

Ici des informations additionnelles:

"pyinstaller" is analyzing a python script and creates an executable containing
all needed modules and libraries to run the script on a target system. Therefor
all imports are recursively scanned. You can have "hidden" imports using 
__import__,
exec or eval. To solve such issues you add a file to the hooks package of
pyinstaller providing the not so obviously imports in a global list named
"hiddenimports". But there can be more complex scenarios, which are not solvable
with a simple list. "pyinstaller" ships with pre defined "hooks" for some
important python frameworks (Django, SQLAlchemy, pyodbc, reportlab, xml to name
a few).

In my case, I want to package a script "runserver.py", which is importing my app.
The application consists of the usal parts (view, model - nothing special). The
build is creating an executable "runserver.exe". There are some warnings about
delayed imports according the werkzeug module. Executing the "runserver.exe" leads
to an error:

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'


This error lead me to the module "werkzeug.__init__.py".

First I added "werkzeug.exceptions" (and others) to the list of
hidden imports : Same behaviour. Then I tried several ways to tell 
pyinstaller about
werkzeug and its imports. All I've learned: I don't know enough about this domain.

I also posted a ticket on googles pyinstaller group. No answer yet.

Regards,
Wolf