一、安装准备
1、看Esky文档,他支持的是cxfreeze4,而在pypi找到cxfreeze4最多只支持到python3.4版本,我用习惯的是3.6,所以干脆就用经典的2.7版本来开发了。附上esky的github链接:https://github.com/cloudmatrix/esky/
2、pip install esky即可安装Esky,对应的cxfreeze的whl下载路径:https://pypi.org/project/cx_Freeze/4.3.4/#files,然后直接pip install cx_Freeze-4.3.3-cp27-none-win32.whl即可,whl根据你的python版本和电脑位数选择下载即可。安装后进到python目录下面的Scripts文件夹,找到cxfreeze-postinstall文件,python cxfreeze-postinstall运行一下,最后在cmd测试 cxfreeze -h 成功即证明安装成功,cxfreeze --version可以查看版本。
二、开发阶段
1、直接用wx_python做一个简易界面,也是参考了http://www.blog.pythonlibrary.org/2013/07/12/wxpython-updating-your-application-with-esky/ 里面的用法,代码如下(之前做的一个东西删减后的代码,可以运行):
#coding=utf-8
import os,random,sys
import wx,ctypes
from wx.lib.softwareupdate import SoftwareUpdate #wx_python内置了esky
from multiprocessing import Process,Value
from version import VERSION #存放版本号
class OrderCtrl(wx.App, SoftwareUpdate):
"""
The Main Class
"""
#----------------------------------------------------------------------
def __init__(self, redirect=False, filename=None):
wx.App.__init__(self, redirect, filename)
BASEURL = "http://10.5.9.222:8080/cw" #新版本存放地方
self.InitUpdates(BASEURL,
BASEURL + "/" + 'ChangeLog.txt') #升级说明文件ChangeLog测试后写不进更新记录,暂时也找不到解决方法,但是写了这个参数就带上这个文件
self.SetAppDisplayName('easyOrder')
self.CheckForUpdate(silentUnlessUpdate=True)#监测到新版本就更新,不然不展示更新
self.frame = wx.Frame(None, -1,title='easyOrder'+VERSION,style=wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX)
self.frame.SetMinSize((600, 600))
self.frame.SetMaxSize((600, 600))
self.panel = wx.Panel(self.frame)
self.icon = wx.Icon('show.ico', wx.BITMAP_TYPE_ICO)
self.frame.SetIcon(self.icon)
self.createWidgets()
self.frame.Show()
#----------------------------------------------------------------------
def createWidgets(self):
ticketLbl = wx.StaticText(self.panel, label='专票流水号码',pos=(60,33),size=(60,-1))#pos=(300,200) 控件位置
self.number1 = wx.TextCtrl(self.panel, pos=(130,30),size=(80,-1),style=(wx.TE_READONLY))
numberLbl = wx.StaticText(self.panel, label='普票流水号码',pos=(270,33),size=(60,-1))
self.number2 = wx.TextCtrl(self.panel, pos=(340,30),size=(80,-1),style=(wx.TE_READONLY))
#根据导出的附件一,进行一多分离
excelLbl = wx.StaticText(self.panel, label='TAXMS系统数据',pos=(30,85),size=(90,-1))
self.excelPath1 = wx.TextCtrl(self.panel, pos=(130,80),size=(300,32))
self.excelBtn1 = wx.Button(self.panel, label='导入',pos=(450,78),size=(50,-1))
#反导入前的数据
excelLbl = wx.StaticText(self.panel, label='开票系统数据',pos=(30,135),size=(90,-1))
self.excelPath2 = wx.TextCtrl(self.panel, pos=(130,130),size=(300,32))
self.excelBtn2 = wx.Button(self.panel, label='导入',pos=(450,128),size=(50,-1))
#生成模板让导入开票系统
excelLbl1 = wx.StaticText(self.panel, label='大发数据',pos=(30,185),size=(90,-1))
self.excelPath3 = wx.TextCtrl(self.panel, pos=(130,180),size=(300,32))
self.excelBtn3 = wx.Button(self.panel, label='导入',pos=(450,178),size=(50,-1))
#输入框和匹配框+语音提醒
########## 多行文本框 ##########
inputLbl = wx.StaticText(self.panel, label='输入框',pos=(30,340),size=(90,-1))
# self.area_text = wx.TextCtrl(self.panel, -1, '', pos=(30,270),size=(200, 40),style=wx.TE_PROCESS_ENTER)
self.area_text = wx.TextCtrl(self.panel, -1, '', (30, 370), (200, 40), wx.TE_MULTILINE)
self.area_text.SetInsertionPoint(0)
#只读显示运单号和发票号
showLbl1 = wx.StaticText(self.panel, label='运单号',pos=(30,420),size=(90,-1))
self.show_text1 = wx.TextCtrl(self.panel, -1, '', pos=(30,440),size=(200, 40),
style=(wx.TE_READONLY))
self.show_text1.SetInsertionPoint(0)
showLbl2 = wx.StaticText(self.panel, label='发票号',pos=(270,340),size=(90,-1))
self.show_text2 = wx.TextCtrl(self.panel, -1, pos=(270,370),size=(200, 110),
style=(wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL))
self.show_text2.SetInsertionPoint(0)
self.startBtn = wx.Button(self.panel, label='启动匹配功能',pos=(250,500),size=(80,-1))#size=(400,40) 控件宽高,-1为默认
self.mainSizer = wx.BoxSizer(wx.VERTICAL)#垂直方向
self.mainSizer.Fit(self.frame)
self.panel.Layout()
def OnExit(self):
#wx.App类方法
return 0
if __name__ == '__main__':
app = OrderCtrl()
app.MainLoop()
2、撰写setup.py,通过此文件进行打包参数的控制,如下:
#coding=utf-8
from esky import bdist_esky
from setuptools import setup
from version import VERSION
# Common settings
# python -m SimpleHTTPServer
exeICON = 'show.ico' #打包成exe的图标
NAME = "easyOrder" #打包后显示的文件名
FREEZER ='cx_Freeze'
# "includes": [""] #引用额外的包
FREEZER_OPTIONS = {
"excludes": ["tkinter"],
"includes" : ["pyttsx3.drivers.sapi5","win32com.server.util"],
"packages": ["wx"]
};
APP = [bdist_esky.Executable("test_esky.py", #出文件入口
gui_only=True,#不显示cmd窗口
icon=exeICON,
)]
#show.icon、config.txt:打包后保留的文件
DATA_FILES = [('',['show.ico','config.txt'] )]
ESKY_OPTIONS = dict( freezer_module = FREEZER,
freezer_options = FREEZER_OPTIONS,
enable_appdata_dir = False,
bundle_msvcrt = False,
)
# Build the app and the esky bundle
setup( name = NAME,
version = VERSION,
scripts = APP,
data_files = DATA_FILES,
options = dict(bdist_esky=ESKY_OPTIONS),
)
三、打包,直接用命令行,在同级路径下:python setup.py bdist_esky 即可打包。打包成功后如下:
包里面的内容:
四、更新
修改新版本后,在version.py里面把VERSION参数更新一下,例如把0.1.8.2更新到0.1.8.3,重新 python setup.py bdist_esky 打包,然后把新版本放在BASEURL下面(前提是你的url可以通过http访问),在里面新建ChangeLog.txt文件,这时候,你重新打开旧版本就可以检测到更新了(ps:打包的NAME = "easyOrder" 这个参数前面更新要一致?不然检测不到版本)