using cx_freeze build simple matplotlib applications work great, i'm running problem when attempting create standalone executable tkinter & matplotlib app.
here's minimal example reproduce error:
#!/usr/bin/env python import matplotlib matplotlib.use('tkagg') numpy import arange, sin, pi matplotlib.backends.backend_tkagg import figurecanvastkagg, navigationtoolbar2tkagg # implement default mpl key bindings matplotlib.backend_bases import key_press_handler matplotlib.figure import figure import sys if sys.version_info[0] < 3: import tkinter tk else: import tkinter tk root = tk.tk() root.wm_title("embedding in tk") f = figure(figsize=(5, 4), dpi=100) = f.add_subplot(111) t = arange(0.0, 3.0, 0.01) s = sin(2*pi*t) a.plot(t, s) # tk.drawingarea canvas = figurecanvastkagg(f, master=root) canvas.show() canvas.get_tk_widget().pack(side=tk.top, fill=tk.both, expand=1) toolbar = navigationtoolbar2tkagg(canvas, root) toolbar.update() canvas._tkcanvas.pack(side=tk.top, fill=tk.both, expand=1) def on_key_event(event): print('you pressed %s' % event.key) key_press_handler(event, canvas, toolbar) canvas.mpl_connect('key_press_event', on_key_event) def _quit(): root.quit() # stops mainloop root.destroy() # necessary on windows prevent # fatal python error: pyeval_restorethread: null tstate button = tk.button(master=root, text='quit', command=_quit) button.pack(side=tk.bottom) tk.mainloop() # if put root.destroy() here, cause error if # window closed window manager.
specifically from matplotlib.backends.backend_tkagg import figurecanvastkagg, navigationtoolbar2tkagg
seems causing problem. if run own app, same error if ran 1 above:
traceback (most recent call last): file "c:\anaconda2\lib\site-packages\cx_freeze\initscripts\console.py", line 27, in <module> exec(code, m.__dict__) file "calipso.py", line 25, in <module> file "c:___.py", line 14, in <module> matplotlib.backends.backend_tkagg import figurecanvastkagg file "c:\users\grant\documents\github\vocal\calipso\build\exe.win32-2.7\matplotlib\backends\backend_tkagg.py", line 7, in <module> six.moves import tkinter_filedialog filedialog file "c:\anaconda2\lib\site-packages\six.py", line 203, in load_module mod = mod._resolve() file "c:\anaconda2\lib\site-packages\six.py", line 115, in _resolve return _import_module(self.mod) file "c:\anaconda2\lib\site-packages\six.py", line 82, in _import_module __import__(name) importerror: no module named filedialog
my setup.py
looks like:
import os import sys distutils.core import setup import cx_freeze import matplotlib base = "console" executable = [ cx_freeze.executable("calipso.py", base = base) ] build_exe_options = {"includes":["matplotlib.backends.backend_tkagg", "ccplot.algorithms", "ccplot.hdf", "tkinter", "tkfiledialog"], "include_files":[(matplotlib.get_data_path(), "mpl-data")], "excludes": ["collections.abc"], } cx_freeze.setup( name = "py", options = {"build_exe": build_exe_options}, version = "0.0", description = "standalone", executables = executable )
how can make sure bundle filedialog
?
found fix problem. issue filedialog
separate package tkinter together, script looks like:
import os import sys distutils.core import setup import cx_freeze import matplotlib base = "console" executable = [ cx_freeze.executable("calipso.py", base = base) ] build_exe_options = {"includes":["matplotlib.backends.backend_tkagg", "ccplot.algorithms", "ccplot.hdf"], "packages:" ["tkinter", "tkfiledialog"], "include_files":[(matplotlib.get_data_path(), "mpl-data")], "excludes": ["collections.abc"], } cx_freeze.setup( name = "py", options = {"build_exe": build_exe_options}, version = "0.0", description = "standalone", executables = executable )
Comments
Post a Comment