我一直在尝试使用cx_freeze将wxpython程序转换为exe。在使用cx_freeze之前,程序按预期工作。如果我点击具有matplotlib图形的面板,我会冻结该应用程序关闭。如果我摆脱所有matplotlib代码,exe运行按预期方式。我一直在线上寻找答案但没有成功,所以任何建议都会非常感激。谢谢!
setup.py
import os
import sys
import cx_Freeze
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = 'C:\xxxx\\xxxx\\DLLs\\tcl86t.dll'
os.environ['TK_LIBRARY'] = 'C:\\xxxx\\xxxx\\DLLs\\tk86t.dll'
Mydata_files = [('C:\\xxxx\\xxxx\\', 'pics'),
('C:\\xxxx\\xxxx\\', 'models')]
path = []
includes = ["scipy", "scipy.integrate" ,"scipy.sparse", "scipy.spatial.ckdtree",
"scipy.sparse.csgraph._validation", 'sklearn', 'matplotlib.backends.backend_wxagg',
'matplotlib.figure', 'matplotlib.backends', 'matplotlib', 'numpy',
'pandas', 'numpy.lib.format']
packages = ['matplotlib', 'wx.lib.pubsub', 'wx.lib.agw', 'pandas', 'numpy',
'scipy.stats','scipy', 'sklearn', 'matplotlib.backends.backend_wxagg',
'matplotlib.figure', 'matplotlib.backends', 'matplotlib',
'numpy.lib.format']
excludes = []
base = None
if sys.platform =='win32':
base = 'Win32GUI'
GUI2Exe_Target_1 = Executable(
# what to build
script = "main.py",
initScript = None,
base = base,
targetName = "test.exe"
)
setup(
version = "0.0.1",
description = "test",
author = "X",
name = "test",
options = {"build_exe": {"includes": includes,
"excludes": excludes,
"packages": packages,
"include_files": Mydata_files,
"path": path
}
},
executables = [GUI2Exe_Target_1]
)
matplotlib在.py脚本中导入:
import os
import sys
import wx
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
from wx.lib.pubsub import pub