Cx_freeze exe 故障排除
我用wxpython和boa constructor写了一个应用程序。这个应用程序把类的实例存储在有序字典里(我导入了odict),最后把数据存储在本地机器上的一个shelve文件里。 应用程序运行得很正常,所以我想把它分发出去。 之前我用过pyinstaller,但发现python 2.6现在不完全支持(我自己验证过,因为我的*exe文件不能运行),所以我换成了cx_freeze。新编译的exe文件似乎运行得不错,但没有创建shelve文件。在构建文件夹里的库文件中,我没有看到odict模块,但看到了shelve模块。看起来这就是问题所在,但我不知道为什么odict没有被自动包含进来。运行应用程序时没有错误,所以我也不太确定该如何找到问题。任何建议或提示我都会非常感激。
我使用的是python 2.6.6,wx python 2.8.11,cx_freeze 4.2.2,操作系统是windows XP。
我写了这个例子来尝试确定它是否会写入shelve文件,但在运行cx_freeze后并没有成功……
import wx
import sys
import os
import shelve
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1BUTTON1,
] = [wx.NewId() for _init_ctrls in range(2)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(557, 369), size=wx.Size(400, 250),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(392, 223))
self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1',
name='button1', parent=self, pos=wx.Point(0, 0), size=wx.Size(392,
223), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=wxID_FRAME1BUTTON1)
def __init__(self, parent):
self._init_ctrls(parent)
def OnButton1Button(self, event):
filename='c:\\MakeAShelve.db'
data=[1,2,3,4]
database=shelve.open(filename)
database['data']=data
database.close()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = create(None)
frame.Show()
app.MainLoop()
我运行的设置如下,并执行了python setup.py build
import sys
from cx_Freeze import setup,Executable
includefiles=[]
exe=Executable(
script="ShelveTesting.py",
base="Win32Gui",
)
setup(
name="TimingDiagram",
version="0.2",
description="An Excel Based Timing Diagram Application",
options={'build_exe':{'include_files':includefiles}},
executables=[exe]
)
1 个回答
1
你可以像这样手动添加模块
build_exe_options = {'packages': ['os','sys','shelve'],'include_files':includefiles}
options = {"build_exe": build_exe_options}
注意!! 使用wxpython时需要特别注意一些事项。 http://wiki.wxpython.org/cx_freeze