使用cx_freeze把python打包exe示例
发布时间:2021-06-10 05:36:20
需要使用到的文件wxapp.py, read_file.py, setup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#file: wxapp.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()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#file: read_file.py
class PrintContent(object):
def show_content(self, path):
f = open(path)
for line in f:
print line
f.close()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#file: setup.py
# 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)
打开cmd进入代码所在目录,然后输入:
python setup.py bdist_msi
然后会生成build和dist两个文件夹,build文件夹里存放的是exe可执行文件和所依赖的库,直接把整个文件夹复制给别人就可以通过双击exe文件运行了,dist文件夹下是build文件夹的安装程序,直接传dist文件夹下的安装包给朋友,朋友运行安装包后会得到和build一样的文件夹,路径由用户自己选择
至于setup.py里面的参数选项可以自己去官网查看相应的选项信息
猜你喜欢
- 昨天我的电影网站在生成内容静态页面的时候出了问题,提示下标越界,以前从来没有遇到过的,所以根本不知道是什么东西,于是就到处在网上找答案,但是
- 教你用Python批量查询关键词微信指数。前期准备安装好Python开发环境及Fiddler抓包工具。前期准备安装好Python开发环境及F
- 本人非计算机,亦非心理学,或者交互设计,更非设计专业出身,因此什么都是半桶水。即使如此,依然靠着兴趣寻找乐趣。对于设计,爱之,但没有受过系统
- 动态页面的模拟点击:以斗鱼直播为例:http://www.douyu.com/directory/all爬取每页的房间名、直播类型、主播名称
- 功能1: 爬取西拉ip代理官网上的代理ip环境:python3.8+pycharm库:requests,lxml浏览器:谷歌IP地址:htt
- 本文实例讲述了js+ajax实现获取文件大小的方法。分享给大家供大家参考,具体如下:顾名思义,通过JS和Ajax来获取上传文件的大小,在上传
- 导言到目前为止的讨论编辑DataList的教程里,没有包含任何验证用户的输入,即使是用户非法输入— 遗漏了product的name或者负的p
- 零、SQLAlchemy是什么?SQLAlchemy的官网上写着它的介绍文字:SQLAlchemy is the Python SQL to
- 一、下载anaconda第一步当然是下载anaconda了,官方网站的下载需要用迅雷才能快点,或者直接到清华大学镜像站下载。当然这里推荐脚本
- Python应用编程需要用到的针对不同数据库引擎的数据库接口:http://wiki.python.org/moin/DatabaseInt
- 从实时视频流中识别出人脸区域,从原理上看,其依然属于机器学习的领域之一,本质上与谷歌利用深度学习识别出猫没有什么区别。程序通过大量的人脸图片
- 图像噪声是指存在于图像数据中的不必要的或多余的干扰信息。在噪声的概念中,通常采用信噪比(Signal-Noise Rate, S
- 核心代码:#!/usr/bin/python# -*- coding: UTF-8 -*-import smtplibimport osim
- 本文借用HTML的css语法,将样式表应用到窗口部件。这里只是个简单的例子,实际上样式表的语法很丰富。以下类似于css: StyleShee
- <form name="frm"><select name=school onchange="
- 前言超参调优是“模型调优”(Model Tuning)阶段最主要的工作,是直接影响模型最终效果的关键
- 一、访问者模式(Visitor Pattern)数据结构中保存着许多元素,当我们希望改变一种对元素的处理方式时,要避免重复的修改数据结构。那
- php获取图片的exif信息,php自带一个exif_read_data函数可以用来读取图片的exif信息,代码来自php手册<?ph
- 1.算法:(设查找的数组期间为array[low, high])(1)确定该期间的中间位置K(2)将查找的值T与array[k]比较。若相等
- (1) 单人脸情况import cv2import dlibpath = "1.jpg"img = cv2.imread