pyinstaller, matplotlib + pygtk,pyqt4,wxpython

553 views
Skip to first unread message

Jon Roadley-Battin

unread,
Mar 19, 2012, 7:37:53 AM3/19/12
to pyins...@googlegroups.com
Is there some means to limit what modules pyinstaller will include.

I have pygtk,pyqt4 and wxpython installed on my windows machine and
for a script which uses matplotlib (which has pygtk,pyqt4,wxpython,tk
support) it bundles files for all the supported toolkits.
within the main script I have


...
import gtk
import gobject

from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as
FigureCanvas
from matplotlib.backends.backend_gtkagg import
NavigationToolbar2GTKAgg as NavigationToolbar
...
and it only load gtk when run from the *.py.

Any help to limit this would be grateful, talking about the difference
between a 15meg bundled and a 30meg bundled

Martin Zibricky

unread,
Mar 19, 2012, 4:44:11 PM3/19/12
to pyins...@googlegroups.com
Jon Roadley-Battin píše v Po 19. 03. 2012 v 11:37 +0000:

> Any help to limit this would be grateful, talking about the difference
> between a 15meg bundled and a 30meg bundled

This is probably caused by matplotlib trying to detect several backends
and pyinstaller detects that it import PyQt4, gtk and wxpython.

There is no specific option for pyinstaller.

One option could be to have python environment with only one library.

Martin Zibricky

unread,
Mar 20, 2012, 9:48:52 AM3/20/12
to pyins...@googlegroups.com
Jon Roadley-Battin píše v Po 19. 03. 2012 v 11:37 +0000:
> Any help to limit this would be grateful, talking about the difference
> between a 15meg bundled and a 30meg bundled

the hook file for matplotlib.backend includes hardcoded list of all
backends. Probably to customize this hook file could solve your issue.

./PyInstaller/hooks/hook-matplotlib.backends.py

Naib

unread,
Sep 5, 2012, 8:50:40 AM9/5/12
to pyins...@googlegroups.com
Sorry for the long delay in a reply, I have only just come back to working on this
It seems matplotlib isn't the only place resulting in qt4 and Tk being pulled in ( I edited the file in question as well as hookutils: all_bk = ['GTK','GTKAgg','GTKCairo']  instead of: all_bk = eval_statement('import matplotlib; print matplotlib.rcsetup.all_backends') )

something is still pulling in pyqt4 and pyTk. It has to be matplotlib (its the only module which can utilise these other toolkits).
Any other suggestions as to where an override could be added?

Martin Zibricky

unread,
Sep 5, 2012, 9:04:07 AM9/5/12
to pyins...@googlegroups.com
Naib píše v St 05. 09. 2012 v 05:50 -0700:
> something is still pulling in pyqt4 and pyTk. It has to be matplotlib
> (its the only module which can utilise these other toolkits).


> Any other suggestions as to where an override could be added?

Look at the following file and add similar hook() function to the
matplotlib hook and then replace 'ImageTk' with the modules you want to
ignore.

./PyInstaller/hooks/shared_PIL_SpiderImagePlugin.py

Naib

unread,
Sep 10, 2012, 5:26:01 AM9/10/12
to pyins...@googlegroups.com
Apologies for being really annoying but it seems Matplotlib is as annoying as me. I have tried doing something along these lines in the matplotlob.backends file. such hook methods do not seem to work since the module that is returned is matplotlib (ie the parent module) and not dependancies. 

 I have gone as far as  

def matplotlib_backends():
    """
    Return matplotlib backends availabe in current Python installation.

    All matplotlib backends are hardcoded. We have to try import them
    and return the list of successfully imported backends.
    """
    all_bk = eval_statement('import matplotlib; print matplotlib.rcsetup.all_backends')
    # only use the ones we want otherwise exe grows too big
    all_bk = ['GTK']#,'GTKAgg','GTKCairo']
    avail_bk = []
    import_statement = """
...


within hookutils.py (and it shows only backend_gtk is being selected). its just there seems to be other methods that either pyinstaller or matplotlib is reporting possible backend and as such qt4 and tk are still being pulled in.
I can uninstall qt4 for now (but I am in the process of converting to pyqt4 so kind of need it). 

I have done --log-level=DEBUG and I can see it has found qt4 and tkinter.
Reply all
Reply to author
Forward
0 new messages