4

我使用 wxpython 和 boa 构造函数编写了一个应用程序。此应用程序将类实例存储在有序字典中(我导入 odict),并最终将数据存储在本地机器上的搁架中。该应用程序按我的预期运行,所以我想分发它。之前我用过pyinstaller,但是了解到目前python 2.6不完全支持(我验证过,因为我的*exe没有工作)所以我切换到cx_freeze。我新编译的 exe 似乎运行良好,但没有创建搁置文件。查看构建文件夹中的库文件,我没有看到 odict 模块。我确实看到搁置。似乎这是问题所在,但我不知道为什么不自动包含 odict 。运行应用程序时我没有收到任何错误,所以我不确定如何查找问题。

在 Windows XP 上使用 python 2.6.6、wx python 2.8.11、cx_freeze 4.2.2。

我写了这个例子来尝试确定它是否会写入搁置文件并且在运行 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]
     )
4

1 回答 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

于 2013-09-13T21:27:45.427 回答