加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – Cx_freeze exe故障排除

发布时间:2020-12-20 13:22:07 所属栏目:Python 来源:网络整理
导读:我使用wx python和boa构造函数编写了一个应用程序.此应用程序将类实例存储在有序字典中(我导入odict)并最终将数据存储在本地计算机上的搁置中. ??应用程序按我的预期运行,所以我想分发它. ??以前,我已经使用过pyinstaller但是已经知道python 2.6目前还没有完
我使用wx python和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构建执行

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读