1、下载并安装py2exe,可下载最新版本。
2、编写安装脚本,比较简单,不过多解释,如下:
Screenshot_setup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
includes = ["encodings", "encodings.*"]
data_files = ['CameraDll.dll']
options = {"py2exe":
{ "compressed": 1,
"optimize": 2,
"bundle_files": 1,
"includes": includes
}
}
setup(
version = "1.0",
description = "Screenshot Tool",
name = "Screenshot Tool",
options = options,
zipfile=None,
data_files = data_files,
console=[{"script": "Screenshot.py", "icon_resources": [(1, "Screenshot.ico")] }]
)
各参数含义见第5小节或执行python命令行下执行help(py2exe)查看。
3、打包程序:
a、将要找包的程序、文件和打包脚本放在同一目录下,如下:
E:\tmp\pyexe_tmp>tree /F
文件夹 PATH 列表
卷序列号码为 0007F240 101F:F68D
E:.
CameraDll.dll
screenshot.ico
Screenshot.py
screenshot_setup.py
没有子文件夹
E:\tmp\pyexe_tmp>
b、执行打包脚本:
E:\tmp\pyexe_tmp>python screenshot_setup.py py2exe
python screenshot_setup.py py2exe
running py2exe
creating E:\tmp\pyexe_tmp\build
creating E:\tmp\pyexe_tmp\build\bdist.win32
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\bundle-2.6
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\temp
creating E:\tmp\pyexe_tmp\dist
*** searching for required modules ***
*** parsing results ***
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
writing byte-compilation script 'e:\tmp\tmp1ecbcw.py'