gpt4 book ai didi

python - Cx_freeze exe 疑难解答

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:13 24 4
gpt4 key购买 nike

我使用 wxpython 和 boa 构造函数编写了一个应用程序。该应用程序将类实例存储在有序字典中(我导入了 odict),并最终将数据存储在本地机器上的一个 shelve 中。 该应用程序按预期运行,因此我想分发它。 之前,我使用过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]
)

最佳答案

你总是可以像这样手动包含模块

build_exe_options = {'packages': ['os','sys','shelve'],'include_files':includefiles}
options = {"build_exe": build_exe_options}

注意!!使用 wxpython 时需要特别小心。 http://wiki.wxpython.org/cx_freeze

关于python - Cx_freeze exe 疑难解答,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4958137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com