• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > 使用cx_freeze把python打包exe示例

使用cx_freeze把python打包exe示例

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了cx freeze python3,cx freeze python3.5,cx freeze python,cx freeze,cx freeze下载等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

需要使用到的文件wxapp.py, read_file.py, setup.py

import wx
import os
import sys
import read_file


class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, title='Hello from cx_Freeze')
        panel = wx.Panel(self)
        closeMeButton = wx.Button(panel, -1, 'Close Me')
        wx.EVT_BUTTON(self, closeMeButton.GetId(), self.OnCloseMe)
        wx.EVT_CLOSE(self, self.OnCloseWindow)
        pushMeButton = wx.Button(panel, -1, 'Push Me')
        wx.EVT_BUTTON(self, pushMeButton.GetId(), self.OnPushMe)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(closeMeButton, flag=wx.ALL, border=20)
        sizer.Add(pushMeButton, flag=wx.ALL, border=20)
        panel.SetSizer(sizer)
        topSizer = wx.BoxSizer(wx.VERTICAL)
        topSizer.Add(panel, flag=wx.ALL | wx.EXPAND)
        topSizer.Fit(self)

    def OnCloseMe(self, event):
        obj = read_file.PrintContent()
        if getattr(sys, 'frozen', None):
            path = os.path.dirname(sys.executable)
        else:
            path = os.path.dirname(__file__)
        path = os.path.join(path, "read_file.py")
        obj.show_content(path)

    def OnPushMe(self, event):
        wx.MessageBox('I was pushed!', 'Informational message')

    def OnCloseWindow(self, event):
        self.Destroy()


class App(wx.App):
    def OnInit(self):
        frame = Frame()
        frame.Show(True)
        self.SetTopWindow(frame)
        return True


app = App(1)
app.MainLoop()
</div>

class PrintContent(object):
    def show_content(self, path):
        f = open(path)
        for line in f:
            print line
        f.close()
</div>

# A simple setup script to create an executable running wxPython. This also
# demonstrates the method for creating a Windows executable that does not have
# an associated console.
#
# wxapp.py is a very simple 'Hello, world' type wxPython application
#
# Run the build process by running the command 'python setup.py build'
#
# If everything works well you should find a subdirectory in the build
# subdirectory that contains the files needed to run the application
import sys
from cx_Freeze import setup, Executable

build_exe_options = {"optimize": 2,
                     "include_files": ["read_file.py"]}

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

executables = [Executable(script='wxapp.py',
               base=base,
               targetName="Demo.exe",
               compress=True,
               icon="py.ico")]

setup(name='wxapp',
      version='0.1',
      description='Sample cx_Freeze wxPython script',
      options = {"build_exe": build_exe_options},
      executables=executables)
</div>

打开cmd进入代码所在目录,然后输入:

然后会生成build和dist两个文件夹,build文件夹里存放的是exe可执行文件和所依赖的库,直接把整个文件夹复制给别人就可以通过双击exe文件运行了,dist文件夹下是build文件夹的安装程序,直接传dist文件夹下的安装包给朋友,朋友运行安装包后会得到和build一样的文件夹,路径由用户自己选择

至于setup.py里面的参数选项可以自己去官网查看相应的选项信息

</div>

您可能想查找下面的文章:

  • python安装cx_Oracle模块常见问题与解决方法
  • python cx_Oracle模块的安装和使用详细介绍
  • Python cx_freeze打包工具处理问题思路及解决办法
  • Python使用cx_Oracle模块将oracle中数据导出到csv文件的方法
  • 使用cx_freeze把python打包exe示例

相关文章

  • Python部署web开发程序的几种方法
  • Python导出DBF文件到Excel的方法
  • Python环境下搭建属于自己的pip源的教程
  • 使用Python读写及压缩和解压缩文件的示例
  • python的描述符(descriptor)、装饰器(property)造成的一个无限递归问题分享
  • Python编程生成随机用户名及密码的方法示例
  • Python编程中的文件操作攻略
  • Python制作爬虫采集小说
  • python 参数列表中的self 显式不等于冗余
  • Python的迭代器和生成器使用实例

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python实现脚本锁功能(同时只能执行一个脚本)
    • python paramiko实现ssh远程访问的方法
    • 以一个投票程序的实例来讲解Python的Django框架使用
    • Python操作MySQL数据库9个实用实例
    • Python爬虫利用cookie实现模拟登陆实例详解
    • Python环境下安装使用异步任务队列包Celery的基础教程
    • Python装饰器decorator用法实例
    • python实现简单的计时器功能函数
    • Python 爬虫爬取指定博客的所有文章
    • Python中正则表达式的详细教程

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有