pyinstaller / pyinstaller

Freeze (package) Python programs into stand-alone executables
http://www.pyinstaller.org
Other
11.5k stars 1.93k forks source link

Matplotlib environment variable hook makes app slow #3472

Open rpaulo opened 6 years ago

rpaulo commented 6 years ago

pyinstaller has a hook to change the matplotlib config environment variable to a random directory every time the program starts: pyi_rth_mplconfig.py

This hook is a hack to avoid some other problem which I can't quite figure out but it was added in https://github.com/pyinstaller/pyinstaller/commit/213bfc3923055cfc18ba7248db5124dbfccea3f9

in artisan, we got a bug report about startup slowness:

https://github.com/artisan-roaster-scope/artisan/issues/178

I've tested pyinstaller+artisan without pyi_rth_mplconfig.py and nothing breaks, so I'm not sure if this hack is still needed.

tallforasmurf commented 6 years ago

Did you read the commit you link to? It seems to me the comments explain its purpose well: that matplotlib records a path to a font cache in the user's home directory, but when a one-file app starts up a second time, that path is out of date -- because PyInstaller unpacks into a different temp folder every time it runs. Refer to how the one-file program works.

rpaulo commented 6 years ago

I did but the hack was around a matplotlib issue wasn’t it? I’m suggesting that issue might have been fixed.

On Apr 19, 2018, at 07:28, Nat Picker notifications@github.com wrote:

Did you read the commit you link to? It seems to me the comments explain its purpose well: that matplotlib records a path to a font cache in the user's home directory, but when a one-file app starts up a second time, that path is out of date -- because PyInstaller unpacks into a different temp folder every time it runs. Refer to how the one-file program works.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

rpaulo commented 6 years ago

I guess in the end what I’m wondering is why this hook is applied to one-folder as well

htgoebel commented 6 years ago

I guess in the end what I’m wondering is why this hook is applied to one-folder as well

For a simple reason: PyInstaller does not support (yet) including/excluding run-time hooks based on options. This might be worth implementing. (Take this as an invitation to do :-) But keep in mind that the "build"/"freeze" is driven by the .spec-file, which has no notion of "one-file" or "one-dir" mode.

As a work-around you can remove the respective run-time hook's script from a.scripts after an Analysis() call. Disclaimer: Untested!