Simple used py2exe
一个实例
# -*- coding:utf-8 -*- # file: setup.py(py2exe) # step: # 1. install py2exe application # 2. build a script 'setup.py' # 3. python setup.py py2exe from distutils.core import setup import py2exe includes = ["PyFetion"] options = {"py2exe": { "compressed": 1, # create a compressed zip archive "optimize": 2, #string or int of optimization level (0, 1, or 2) # 0 = don't optimize (generate .pyc) # 1 = normal optimization (like python -O) # 2 = extra optimization (like python -OO) "includes": includes, #list of module names to include "bundle_files": 1 #bundle dlls in the zipfile or the exe. #Valid levels are 1, 2, or 3 (default) } } setup( version = "2.0", description = "Weather to phone by Fetion", name = "Weather2Fetion", copyright = "no copyright", options = options, zipfile=None, # console=["Weather2Fetion.py"] console=[ { "script" : "Weather2Fetion.py", "icon_resources" : [(1, "wf.ico")] } ] ) ---------------------------------------------------- # setup.py from distutils.core import setup import py2exe setup(console=["hello.py"]) 运行setup.py,记得要传一个参数给它 python setup.py py2exe py2exe会在当前目录下生成两个目录 build和dist build里是一些py2exe运行时产生的中间文件,dist里有最终的可执行文件 library.zip w9xpopen.exe python25.dll hello.exe ---------------------------------------------------- 能不能打包成只有一个文件,hello.exe,这样运行方便些。 ---------------------------------------------------- 加一个 zipfile = None 比如: from distutils.core import setup import py2exe setup( version = "0.5.0", description = "py2exe sample script", name = "py2exe samples", options = {'py2exe': {'optimize': 2, 'bundle_files': 1, "compressed": 1,}}, windows = ["test_wx.py"], console = ["hello.py"], zipfile = None ) ---------------------------------------------------- 呵呵,牛,果然可以,生成三个文件,Hello.exe, MSVCR71.dll, w9xpopen.exe, 把后面两个文件删除,只保留Hello.exe也可以用. 那么,后面两个是什么用的,什么情况下会用到。 ---------------------------------------------------- w9xpopen.exe是给 windows 98 用的。 MSVCR71.dll 是个vc7.1的动态链接库, py2exe生成的exe需要这个动态链接库,不过这个库一般winxp上都是有的。
以上是今天对py2exe的使用学习,成功完成前面Weather2Fetion的编译并部署到服务器上。
-End-