n 本文介绍如何使用py2exe来将python源程序打包成文件。以上一篇文章[《Python:一个多功能的抓图工具开发(附源码)》](http://blog.csdn.net/dyx1024/article/details/7340903)中的源程序为例进行讲述。
1、下载并安装py2exe,可在www.py2exe.org上下载最新版本。
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'
C:\Python26\python.exe -OO e:\tmp\tmp1ecbcw.py
byte-compiling C:\Python26\lib\StringIO.py to StringIO.pyo
byte-compiling C:\Python26\lib\UserDict.py to UserDict.pyo
byte-compiling C:\Python26\lib\__future__.py to __future__.pyo
byte-compiling C:\Python26\lib\_abcoll.py to _abcoll.pyo
byte-compiling C:\Python26\lib\_strptime.py to _strptime.pyo
byte-compiling C:\Python26\lib\_threading_local.py to _threading_local.pyo
byte-compiling C:\Python26\lib\abc.py to abc.pyo
byte-compiling C:\Python26\lib\atexit.py to atexit.pyo
byte-compiling C:\Python26\lib\base64.py to base64.pyo
byte-compiling C:\Python26\lib\bdb.py to bdb.pyo
byte-compiling C:\Python26\lib\bisect.py to bisect.pyo
byte-compiling C:\Python26\lib\calendar.py to calendar.pyo
byte-compiling C:\Python26\lib\cmd.py to cmd.pyo
byte-compiling C:\Python26\lib\codecs.py to codecs.pyo
byte-compiling C:\Python26\lib\collections.py to collections.pyo
byte-compiling C:\Python26\lib\colorsys.py to colorsys.pyo
byte-compiling C:\Python26\lib\copy.py to copy.pyo
byte-compiling C:\Python26\lib\copy_reg.py to copy_reg.pyo
byte-compiling C:\Python26\lib\ctypes\__init__.py to ctypes\__init__.pyo
byte-compiling C:\Python26\lib\ctypes\_endian.py to ctypes\_endian.pyo
byte-compiling C:\Python26\lib\ctypes\wintypes.py to ctypes\wintypes.pyo
byte-compiling C:\Python26\lib\difflib.py to difflib.pyo
byte-compiling C:\Python26\lib\dis.py to dis.pyo
byte-compiling C:\Python26\lib\doctest.py to doctest.pyo
byte-compiling C:\Python26\lib\dummy_thread.py to dummy_thread.pyo
byte-compiling C:\Python26\lib\encodings\__init__.py to encodings\__init__.pyo
byte-compiling C:\Python26\lib\encodings\aliases.py to encodings\aliases.pyo
byte-compiling C:\Python26\lib\encodings\ascii.py to encodings\ascii.pyo
byte-compiling C:\Python26\lib\encodings\base64_codec.py to encodings\base64_codec.pyo
byte-compiling C:\Python26\lib\encodings\big5.py to encodings\big5.pyo
byte-compiling C:\Python26\lib\encodings\big5hkscs.py to encodings\big5hkscs.pyo
byte-compiling C:\Python26\lib\encodings\bz2_codec.py to encodings\bz2_codec.pyo
byte-compiling C:\Python26\lib\encodings\charmap.py to encodings\charmap.pyo
byte-compiling C:\Python26\lib\encodings\cp037.py to encodings\cp037.pyo
byte-compiling C:\Python26\lib\encodings\cp1006.py to encodings\cp1006.pyo
byte-compiling C:\Python26\lib\encodings\cp1026.py to encodings\cp1026.pyo
byte-compiling C:\Python26\lib\encodings\cp1140.py to encodings\cp1140.pyo
byte-compiling C:\Python26\lib\encodings\cp1250.py to encodings\cp1250.pyo
byte-compiling C:\Python26\lib\encodings\cp1251.py to encodings\cp1251.pyo
byte-compiling C:\Python26\lib\encodings\cp1252.py to encodings\cp1252.pyo
byte-compiling C:\Python26\lib\encodings\cp1253.py to encodings\cp1253.pyo
byte-compiling C:\Python26\lib\encodings\cp1254.py to encodings\cp1254.pyo
byte-compiling C:\Python26\lib\encodings\cp1255.py to encodings\cp1255.pyo
byte-compiling C:\Python26\lib\encodings\cp1256.py to encodings\cp1256.pyo
byte-compiling C:\Python26\lib\encodings\cp1257.py to encodings\cp1257.pyo
byte-compiling C:\Python26\lib\encodings\cp1258.py to encodings\cp1258.pyo
byte-compiling C:\Python26\lib\encodings\cp424.py to encodings\cp424.pyo
byte-compiling C:\Python26\lib\encodings\cp437.py to encodings\cp437.pyo
byte-compiling C:\Python26\lib\encodings\cp500.py to encodings\cp500.pyo
byte-compiling C:\Python26\lib\encodings\cp737.py to encodings\cp737.pyo
byte-compiling C:\Python26\lib\encodings\cp775.py to encodings\cp775.pyo
byte-compiling C:\Python26\lib\encodings\cp850.py to encodings\cp850.pyo
byte-compiling C:\Python26\lib\encodings\cp852.py to encodings\cp852.pyo
byte-compiling C:\Python26\lib\encodings\cp855.py to encodings\cp855.pyo
byte-compiling C:\Python26\lib\encodings\cp856.py to encodings\cp856.pyo
byte-compiling C:\Python26\lib\encodings\cp857.py to encodings\cp857.pyo
byte-compiling C:\Python26\lib\encodings\cp860.py to encodings\cp860.pyo
byte-compiling C:\Python26\lib\encodings\cp861.py to encodings\cp861.pyo
byte-compiling C:\Python26\lib\encodings\cp862.py to encodings\cp862.pyo
byte-compiling C:\Python26\lib\encodings\cp863.py to encodings\cp863.pyo
byte-compiling C:\Python26\lib\encodings\cp864.py to encodings\cp864.pyo
byte-compiling C:\Python26\lib\encodings\cp865.py to encodings\cp865.pyo
byte-compiling C:\Python26\lib\encodings\cp866.py to encodings\cp866.pyo
byte-compiling C:\Python26\lib\encodings\cp869.py to encodings\cp869.pyo
byte-compiling C:\Python26\lib\encodings\cp874.py to encodings\cp874.pyo
byte-compiling C:\Python26\lib\encodings\cp875.py to encodings\cp875.pyo
byte-compiling C:\Python26\lib\encodings\cp932.py to encodings\cp932.pyo
byte-compiling C:\Python26\lib\encodings\cp949.py to encodings\cp949.pyo
byte-compiling C:\Python26\lib\encodings\cp950.py to encodings\cp950.pyo
byte-compiling C:\Python26\lib\encodings\euc_jis_2004.py to encodings\euc_jis_2004.pyo
byte-compiling C:\Python26\lib\encodings\euc_jisx0213.py to encodings\euc_jisx0213.pyo
byte-compiling C:\Python26\lib\encodings\euc_jp.py to encodings\euc_jp.pyo
byte-compiling C:\Python26\lib\encodings\euc_kr.py to encodings\euc_kr.pyo
byte-compiling C:\Python26\lib\encodings\gb18030.py to encodings\gb18030.pyo
byte-compiling C:\Python26\lib\encodings\gb2312.py to encodings\gb2312.pyo
byte-compiling C:\Python26\lib\encodings\gbk.py to encodings\gbk.pyo
byte-compiling C:\Python26\lib\encodings\hex_codec.py to encodings\hex_codec.pyo
byte-compiling C:\Python26\lib\encodings\hp_roman8.py to encodings\hp_roman8.pyo
byte-compiling C:\Python26\lib\encodings\hz.py to encodings\hz.pyo
byte-compiling C:\Python26\lib\encodings\idna.py to encodings\idna.pyo
byte-compiling C:\Python26\lib\encodings\iso2022_jp.py to encodings\iso2022_jp.pyo
byte-compiling C:\Python26\lib\encodings\iso2022_jp_1.py to encodings\iso2022_jp_1.pyo
byte-compiling C:\Python26\lib\encodings\iso2022_jp_2.py to encodings\iso2022_jp_2.pyo
byte-compiling C:\Python26\lib\encodings\iso2022_jp_2004.py to encodings\iso2022_jp_2004.pyo
byte-compiling C:\Python26\lib\encodings\iso2022_jp_3.py to encodings\iso2022_jp_3.pyo
byte-compiling C:\Python26\lib\encodings\iso2022_jp_ext.py to encodings\iso2022_jp_ext.pyo
byte-compiling C:\Python26\lib\encodings\iso2022_kr.py to encodings\iso2022_kr.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_1.py to encodings\iso8859_1.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_10.py to encodings\iso8859_10.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_11.py to encodings\iso8859_11.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_13.py to encodings\iso8859_13.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_14.py to encodings\iso8859_14.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_15.py to encodings\iso8859_15.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_16.py to encodings\iso8859_16.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_2.py to encodings\iso8859_2.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_3.py to encodings\iso8859_3.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_4.py to encodings\iso8859_4.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_5.py to encodings\iso8859_5.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_6.py to encodings\iso8859_6.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_7.py to encodings\iso8859_7.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_8.py to encodings\iso8859_8.pyo
byte-compiling C:\Python26\lib\encodings\iso8859_9.py to encodings\iso8859_9.pyo
byte-compiling C:\Python26\lib\encodings\johab.py to encodings\johab.pyo
byte-compiling C:\Python26\lib\encodings\koi8_r.py to encodings\koi8_r.pyo
byte-compiling C:\Python26\lib\encodings\koi8_u.py to encodings\koi8_u.pyo
byte-compiling C:\Python26\lib\encodings\latin_1.py to encodings\latin_1.pyo
byte-compiling C:\Python26\lib\encodings\mac_arabic.py to encodings\mac_arabic.pyo
byte-compiling C:\Python26\lib\encodings\mac_centeuro.py to encodings\mac_centeuro.pyo
byte-compiling C:\Python26\lib\encodings\mac_croatian.py to encodings\mac_croatian.pyo
byte-compiling C:\Python26\lib\encodings\mac_cyrillic.py to encodings\mac_cyrillic.pyo
byte-compiling C:\Python26\lib\encodings\mac_farsi.py to encodings\mac_farsi.pyo
byte-compiling C:\Python26\lib\encodings\mac_greek.py to encodings\mac_greek.pyo
byte-compiling C:\Python26\lib\encodings\mac_iceland.py to encodings\mac_iceland.pyo
byte-compiling C:\Python26\lib\encodings\mac_latin2.py to encodings\mac_latin2.pyo
byte-compiling C:\Python26\lib\encodings\mac_roman.py to encodings\mac_roman.pyo
byte-compiling C:\Python26\lib\encodings\mac_romanian.py to encodings\mac_romanian.pyo
byte-compiling C:\Python26\lib\encodings\mac_turkish.py to encodings\mac_turkish.pyo
byte-compiling C:\Python26\lib\encodings\mbcs.py to encodings\mbcs.pyo
byte-compiling C:\Python26\lib\encodings\palmos.py to encodings\palmos.pyo
byte-compiling C:\Python26\lib\encodings\ptcp154.py to encodings\ptcp154.pyo
byte-compiling C:\Python26\lib\encodings\punycode.py to encodings\punycode.pyo
byte-compiling C:\Python26\lib\encodings\quopri_codec.py to encodings\quopri_codec.pyo
byte-compiling C:\Python26\lib\encodings\raw_unicode_escape.py to encodings\raw_unicode_escape.pyo
byte-compiling C:\Python26\lib\encodings\rot_13.py to encodings\rot_13.pyo
byte-compiling C:\Python26\lib\encodings\shift_jis.py to encodings\shift_jis.pyo
byte-compiling C:\Python26\lib\encodings\shift_jis_2004.py to encodings\shift_jis_2004.pyo
byte-compiling C:\Python26\lib\encodings\shift_jisx0213.py to encodings\shift_jisx0213.pyo
byte-compiling C:\Python26\lib\encodings\string_escape.py to encodings\string_escape.pyo
byte-compiling C:\Python26\lib\encodings\tis_620.py to encodings\tis_620.pyo
byte-compiling C:\Python26\lib\encodings\undefined.py to encodings\undefined.pyo
byte-compiling C:\Python26\lib\encodings\unicode_escape.py to encodings\unicode_escape.pyo
byte-compiling C:\Python26\lib\encodings\unicode_internal.py to encodings\unicode_internal.pyo
byte-compiling C:\Python26\lib\encodings\utf_16.py to encodings\utf_16.pyo
byte-compiling C:\Python26\lib\encodings\utf_16_be.py to encodings\utf_16_be.pyo
byte-compiling C:\Python26\lib\encodings\utf_16_le.py to encodings\utf_16_le.pyo
byte-compiling C:\Python26\lib\encodings\utf_32.py to encodings\utf_32.pyo
byte-compiling C:\Python26\lib\encodings\utf_32_be.py to encodings\utf_32_be.pyo
byte-compiling C:\Python26\lib\encodings\utf_32_le.py to encodings\utf_32_le.pyo
byte-compiling C:\Python26\lib\encodings\utf_7.py to encodings\utf_7.pyo
byte-compiling C:\Python26\lib\encodings\utf_8.py to encodings\utf_8.pyo
byte-compiling C:\Python26\lib\encodings\utf_8_sig.py to encodings\utf_8_sig.pyo
byte-compiling C:\Python26\lib\encodings\uu_codec.py to encodings\uu_codec.pyo
byte-compiling C:\Python26\lib\encodings\zlib_codec.py to encodings\zlib_codec.pyo
byte-compiling C:\Python26\lib\functools.py to functools.pyo
byte-compiling C:\Python26\lib\genericpath.py to genericpath.pyo
byte-compiling C:\Python26\lib\getopt.py to getopt.pyo
byte-compiling C:\Python26\lib\gettext.py to gettext.pyo
byte-compiling C:\Python26\lib\heapq.py to heapq.pyo
byte-compiling C:\Python26\lib\inspect.py to inspect.pyo
byte-compiling C:\Python26\lib\keyword.py to keyword.pyo
byte-compiling C:\Python26\lib\linecache.py to linecache.pyo
byte-compiling C:\Python26\lib\locale.py to locale.pyo
byte-compiling C:\Python26\lib\new.py to new.pyo
byte-compiling C:\Python26\lib\ntpath.py to ntpath.pyo
byte-compiling C:\Python26\lib\opcode.py to opcode.pyo
byte-compiling C:\Python26\lib\optparse.py to optparse.pyo
byte-compiling C:\Python26\lib\os.py to os.pyo
byte-compiling C:\Python26\lib\os2emxpath.py to os2emxpath.pyo
byte-compiling C:\Python26\lib\pdb.py to pdb.pyo
byte-compiling C:\Python26\lib\pickle.py to pickle.pyo
byte-compiling C:\Python26\lib\posixpath.py to posixpath.pyo
byte-compiling C:\Python26\lib\pprint.py to pprint.pyo
byte-compiling C:\Python26\lib\pyhk.py to pyhk.pyo
byte-compiling C:\Python26\lib\quopri.py to quopri.pyo
byte-compiling C:\Python26\lib\random.py to random.pyo
byte-compiling C:\Python26\lib\re.py to re.pyo
byte-compiling C:\Python26\lib\repr.py to repr.pyo
byte-compiling C:\Python26\lib\shlex.py to shlex.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\BmpImagePlugin.py to PIL\BmpImagePlugin.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\GifImagePlugin.py to PIL\GifImagePlugin.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\GimpGradientFile.py to PIL\GimpGradientFile.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\GimpPaletteFile.py to PIL\GimpPaletteFile.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\Image.py to PIL\Image.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\ImageChops.py to PIL\ImageChops.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\ImageColor.py to PIL\ImageColor.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\ImageFile.py to PIL\ImageFile.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\ImageGrab.py to PIL\ImageGrab.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\ImageMode.py to PIL\ImageMode.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\ImagePalette.py to PIL\ImagePalette.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\ImageShow.py to PIL\ImageShow.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\JpegImagePlugin.py to PIL\JpegImagePlugin.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\PaletteFile.py to PIL\PaletteFile.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\PngImagePlugin.py to PIL\PngImagePlugin.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\PpmImagePlugin.py to PIL\PpmImagePlugin.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\TiffImagePlugin.py to PIL\TiffImagePlugin.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\TiffTags.py to PIL\TiffTags.pyo
byte-compiling C:\Python26\lib\site-packages\PIL\__init__.py to PIL\__init__.pyo
byte-compiling C:\Python26\lib\site-packages\pyHook\HookManager.py to pyHook\HookManager.pyo
byte-compiling C:\Python26\lib\site-packages\pyHook\__init__.py to pyHook\__init__.pyo
byte-compiling C:\Python26\lib\site-packages\pyHook\cpyHook.py to pyHook\cpyHook.pyo
byte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py to wx\__init__.pyo
byte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\__version__.py to wx\__version__.pyo
byte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py to wx\_controls.pyo
byte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py to wx\_core.pyo
byte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py to wx\_gdi.pyo
byte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py to wx\_misc.pyo
byte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py to wx\_windows.pyo
byte-compiling C:\Python26\lib\site-packages\zipextimporter.py to zipextimporter.pyo
byte-compiling C:\Python26\lib\sre.py to sre.pyo
byte-compiling C:\Python26\lib\sre_compile.py to sre_compile.pyo
byte-compiling C:\Python26\lib\sre_constants.py to sre_constants.pyo
byte-compiling C:\Python26\lib\sre_parse.py to sre_parse.pyo
byte-compiling C:\Python26\lib\stat.py to stat.pyo
byte-compiling C:\Python26\lib\string.py to string.pyo
byte-compiling C:\Python26\lib\stringprep.py to stringprep.pyo
byte-compiling C:\Python26\lib\struct.py to struct.pyo
byte-compiling C:\Python26\lib\subprocess.py to subprocess.pyo
byte-compiling C:\Python26\lib\tempfile.py to tempfile.pyo
byte-compiling C:\Python26\lib\textwrap.py to textwrap.pyo
byte-compiling C:\Python26\lib\threading.py to threading.pyo
byte-compiling C:\Python26\lib\token.py to token.pyo
byte-compiling C:\Python26\lib\tokenize.py to tokenize.pyo
byte-compiling C:\Python26\lib\traceback.py to traceback.pyo
byte-compiling C:\Python26\lib\types.py to types.pyo
byte-compiling C:\Python26\lib\unittest.py to unittest.pyo
byte-compiling C:\Python26\lib\warnings.py to warnings.pyo
C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated
import sets
removing e:\tmp\tmp1ecbcw.py
***copy extensions ***
copying C:\Python26\DLLs\_ctypes.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\DLLs\bz2.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\DLLs\select.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\DLLs\unicodedata.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\lib\site-packages\PIL\_imaging.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\PIL
copying C:\Python26\lib\site-packages\pyHook\_cpyHook.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\pyHook
copying C:\Python26\lib\site-packages\win32\_win32sysloader.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\lib\site-packages\win32\win32gui.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_controls_.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\wx
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core_.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\wx
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi_.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\wx
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_misc_.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\wx
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_windows_.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\wx
***copy dlls ***
copying C:\WINDOWS\system32\python26.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\bundle-2.6
setting sys.winver for 'E:\tmp\pyexe_tmp\build\bdist.win32\winexe\bundle-2.6\python26.dll' to 'Screenshot Tool'
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\wxbase28uh_vc.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\WINDOWS\system32\pythoncom26.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\WINDOWS\system32\pywintypes26.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\wxmsw28uh_core_vc.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\w9xpopen.exe -> E:\tmp\pyexe_tmp\dist
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\wxbase28uh_net_vc.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\wxmsw28uh_adv_vc.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\wxmsw28uh_html_vc.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
***copy data files ***
copying CameraDll.dll -> E:\tmp\pyexe_tmp\dist
copying C:\Python26\lib\site-packages\py2exe\run.exe -> E:\tmp\pyexe_tmp\dist\Screenshot.exe
Adding python26.dll as resource to E:\tmp\pyexe_tmp\dist\Screenshot.exe
The following modules appear to be missing
['ICCProfile', '_grabscreen', '_imaging_gif']
***binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.
Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.
OLEAUT32.dll - C:\WINDOWS\system32\OLEAUT32.dll
USER32.dll - C:\WINDOWS\system32\USER32.dll
SHELL32.dll - C:\WINDOWS\system32\SHELL32.dll
ole32.dll - C:\WINDOWS\system32\ole32.dll
COMDLG32.dll - C:\WINDOWS\system32\COMDLG32.dll
WSOCK32.dll - C:\WINDOWS\system32\WSOCK32.dll
COMCTL32.dll - C:\WINDOWS\system32\COMCTL32.dll
WINMM.dll - C:\WINDOWS\system32\WINMM.dll
msvcrt.dll - C:\WINDOWS\system32\msvcrt.dll
ADVAPI32.dll - C:\WINDOWS\system32\ADVAPI32.dll
GDI32.dll - C:\WINDOWS\system32\GDI32.dll
RPCRT4.dll - C:\WINDOWS\system32\RPCRT4.dll
KERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dll
gdiplus.dll - C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\gdiplus.dll
MSVCP90.dll - C:\WINDOWS\system32\MSVCP90.dll
C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated
import sets
warning: install_data: setup script did not provide a directory for 'CameraDll.dll' -- installing right in 'E:\tmp\pyexe_tmp\dist'
E:\tmp\pyexe_tmp>
~~~
如果打包时提示缺少dll文件,如msvcp90.dll,在网上下载一个放入python安装目录的子目录dlls中即可(如:C:\Python26\DLLs)
c、打包完成后的目录结构如下:
~~~
E:\tmp\pyexe_tmp>tree /F
文件夹 PATH 列表
卷序列号码为 0007F240 101F:F68D
E:.
│ CameraDll.dll
│ screenshot.ico
│ screenshot.py
│ screenshot_setup.py
│
├─build
│ └─bdist.win32
│ └─winexe
│ ├─bundle-2.6
│ │ python26.dll
│ │
│ ├─collect-2.6
│ │ │ abc.pyo
│ │ │ atexit.pyo
│ │ │ base64.pyo
│ │ │ bdb.pyo
│ │ │ bisect.pyo
│ │ │ bz2.pyd
│ │ │ calendar.pyo
│ │ │ cmd.pyo
│ │ │ codecs.pyo
│ │ │ collections.pyo
│ │ │ colorsys.pyo
│ │ │ copy.pyo
│ │ │ copy_reg.pyo
│ │ │ difflib.pyo
│ │ │ dis.pyo
│ │ │ doctest.pyo
│ │ │ dummy_thread.pyo
│ │ │ functools.pyo
│ │ │ genericpath.pyo
│ │ │ getopt.pyo
│ │ │ gettext.pyo
│ │ │ heapq.pyo
│ │ │ inspect.pyo
│ │ │ keyword.pyo
│ │ │ linecache.pyo
│ │ │ locale.pyo
│ │ │ new.pyo
│ │ │ ntpath.pyo
│ │ │ opcode.pyo
│ │ │ optparse.pyo
│ │ │ os.pyo
│ │ │ os2emxpath.pyo
│ │ │ pdb.pyo
│ │ │ pickle.pyo
│ │ │ posixpath.pyo
│ │ │ pprint.pyo
│ │ │ pyhk.pyo
│ │ │ pythoncom26.dll
│ │ │ pywintypes26.dll
│ │ │ quopri.pyo
│ │ │ random.pyo
│ │ │ re.pyo
│ │ │ repr.pyo
│ │ │ select.pyd
│ │ │ shlex.pyo
│ │ │ sre.pyo
│ │ │ sre_compile.pyo
│ │ │ sre_constants.pyo
│ │ │ sre_parse.pyo
│ │ │ stat.pyo
│ │ │ string.pyo
│ │ │ StringIO.pyo
│ │ │ stringprep.pyo
│ │ │ struct.pyo
│ │ │ subprocess.pyo
│ │ │ tempfile.pyo
│ │ │ textwrap.pyo
│ │ │ threading.pyo
│ │ │ token.pyo
│ │ │ tokenize.pyo
│ │ │ traceback.pyo
│ │ │ types.pyo
│ │ │ unicodedata.pyd
│ │ │ unittest.pyo
│ │ │ UserDict.pyo
│ │ │ warnings.pyo
│ │ │ win32gui.pyd
│ │ │ wxbase28uh_net_vc.dll
│ │ │ wxbase28uh_vc.dll
│ │ │ wxmsw28uh_adv_vc.dll
│ │ │ wxmsw28uh_core_vc.dll
│ │ │ wxmsw28uh_html_vc.dll
│ │ │ zipextimporter.pyo
│ │ │ _abcoll.pyo
│ │ │ _ctypes.pyd
│ │ │ _strptime.pyo
│ │ │ _threading_local.pyo
│ │ │ _win32sysloader.pyd
│ │ │ __future__.pyo
│ │ │
│ │ ├─ctypes
│ │ │ wintypes.pyo
│ │ │ _endian.pyo
│ │ │ __init__.pyo
│ │ │
│ │ ├─encodings
│ │ │ aliases.pyo
│ │ │ ascii.pyo
│ │ │ base64_codec.pyo
│ │ │ big5.pyo
│ │ │ big5hkscs.pyo
│ │ │ bz2_codec.pyo
│ │ │ charmap.pyo
│ │ │ cp037.pyo
│ │ │ cp1006.pyo
│ │ │ cp1026.pyo
│ │ │ cp1140.pyo
│ │ │ cp1250.pyo
│ │ │ cp1251.pyo
│ │ │ cp1252.pyo
│ │ │ cp1253.pyo
│ │ │ cp1254.pyo
│ │ │ cp1255.pyo
│ │ │ cp1256.pyo
│ │ │ cp1257.pyo
│ │ │ cp1258.pyo
│ │ │ cp424.pyo
│ │ │ cp437.pyo
│ │ │ cp500.pyo
│ │ │ cp737.pyo
│ │ │ cp775.pyo
│ │ │ cp850.pyo
│ │ │ cp852.pyo
│ │ │ cp855.pyo
│ │ │ cp856.pyo
│ │ │ cp857.pyo
│ │ │ cp860.pyo
│ │ │ cp861.pyo
│ │ │ cp862.pyo
│ │ │ cp863.pyo
│ │ │ cp864.pyo
│ │ │ cp865.pyo
│ │ │ cp866.pyo
│ │ │ cp869.pyo
│ │ │ cp874.pyo
│ │ │ cp875.pyo
│ │ │ cp932.pyo
│ │ │ cp949.pyo
│ │ │ cp950.pyo
│ │ │ euc_jisx0213.pyo
│ │ │ euc_jis_2004.pyo
│ │ │ euc_jp.pyo
│ │ │ euc_kr.pyo
│ │ │ gb18030.pyo
│ │ │ gb2312.pyo
│ │ │ gbk.pyo
│ │ │ hex_codec.pyo
│ │ │ hp_roman8.pyo
│ │ │ hz.pyo
│ │ │ idna.pyo
│ │ │ iso2022_jp.pyo
│ │ │ iso2022_jp_1.pyo
│ │ │ iso2022_jp_2.pyo
│ │ │ iso2022_jp_2004.pyo
│ │ │ iso2022_jp_3.pyo
│ │ │ iso2022_jp_ext.pyo
│ │ │ iso2022_kr.pyo
│ │ │ iso8859_1.pyo
│ │ │ iso8859_10.pyo
│ │ │ iso8859_11.pyo
│ │ │ iso8859_13.pyo
│ │ │ iso8859_14.pyo
│ │ │ iso8859_15.pyo
│ │ │ iso8859_16.pyo
│ │ │ iso8859_2.pyo
│ │ │ iso8859_3.pyo
│ │ │ iso8859_4.pyo
│ │ │ iso8859_5.pyo
│ │ │ iso8859_6.pyo
│ │ │ iso8859_7.pyo
│ │ │ iso8859_8.pyo
│ │ │ iso8859_9.pyo
│ │ │ johab.pyo
│ │ │ koi8_r.pyo
│ │ │ koi8_u.pyo
│ │ │ latin_1.pyo
│ │ │ mac_arabic.pyo
│ │ │ mac_centeuro.pyo
│ │ │ mac_croatian.pyo
│ │ │ mac_cyrillic.pyo
│ │ │ mac_farsi.pyo
│ │ │ mac_greek.pyo
│ │ │ mac_iceland.pyo
│ │ │ mac_latin2.pyo
│ │ │ mac_roman.pyo
│ │ │ mac_romanian.pyo
│ │ │ mac_turkish.pyo
│ │ │ mbcs.pyo
│ │ │ palmos.pyo
│ │ │ ptcp154.pyo
│ │ │ punycode.pyo
│ │ │ quopri_codec.pyo
│ │ │ raw_unicode_escape.pyo
│ │ │ rot_13.pyo
│ │ │ shift_jis.pyo
│ │ │ shift_jisx0213.pyo
│ │ │ shift_jis_2004.pyo
│ │ │ string_escape.pyo
│ │ │ tis_620.pyo
│ │ │ undefined.pyo
│ │ │ unicode_escape.pyo
│ │ │ unicode_internal.pyo
│ │ │ utf_16.pyo
│ │ │ utf_16_be.pyo
│ │ │ utf_16_le.pyo
│ │ │ utf_32.pyo
│ │ │ utf_32_be.pyo
│ │ │ utf_32_le.pyo
│ │ │ utf_7.pyo
│ │ │ utf_8.pyo
│ │ │ utf_8_sig.pyo
│ │ │ uu_codec.pyo
│ │ │ zlib_codec.pyo
│ │ │ __init__.pyo
│ │ │
│ │ ├─PIL
│ │ │ BmpImagePlugin.pyo
│ │ │ GifImagePlugin.pyo
│ │ │ GimpGradientFile.pyo
│ │ │ GimpPaletteFile.pyo
│ │ │ Image.pyo
│ │ │ ImageChops.pyo
│ │ │ ImageColor.pyo
│ │ │ ImageFile.pyo
│ │ │ ImageGrab.pyo
│ │ │ ImageMode.pyo
│ │ │ ImagePalette.pyo
│ │ │ ImageShow.pyo
│ │ │ JpegImagePlugin.pyo
│ │ │ PaletteFile.pyo
│ │ │ PngImagePlugin.pyo
│ │ │ PpmImagePlugin.pyo
│ │ │ TiffImagePlugin.pyo
│ │ │ TiffTags.pyo
│ │ │ _imaging.pyd
│ │ │ __init__.pyo
│ │ │
│ │ ├─pyHook
│ │ │ cpyHook.pyo
│ │ │ HookManager.pyo
│ │ │ _cpyHook.pyd
│ │ │ __init__.pyo
│ │ │
│ │ └─wx
│ │ _controls.pyo
│ │ _controls_.pyd
│ │ _core.pyo
│ │ _core_.pyd
│ │ _gdi.pyo
│ │ _gdi_.pyd
│ │ _misc.pyo
│ │ _misc_.pyd
│ │ _windows.pyo
│ │ _windows_.pyd
│ │ __init__.pyo
│ │ __version__.pyo
│ │
│ └─temp
└─dist
CameraDll.dll
RCXBC.tmp
Screenshot.exe
w9xpopen.exe
E:\tmp\pyexe_tmp>
~~~
我们只需要发布dist 子目录下的Screenshot.exe和CameraDLL.dll即可,包含dll的原因是screenshot.py中调用了这个dll文件。
4、附一个功能完整的打包程序,原文件见:[http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/](http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/)
~~~
from distutils.core import setup
import py2exe
includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
'tk84.dll']
setup(
options = {"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 3,
"dist_dir": "dist",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
windows=['sampleApp.py']
)
~~~
5、各参数简介:
~~~
E:\tmp\pyexe_tmp>python screenshot_setup.py --help py2exe
C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the se
ts module is deprecated
import sets
Common commands: (see '--help-commands' for more)
setup.py build will build the package underneath 'build/'
setup.py install will install the package
Global options:
--verbose (-v) run verbosely (default)
--quiet (-q) run quietly (turns verbosity off)
--dry-run (-n) don't actually do anything
--help (-h) show detailed help message
Options for 'py2exe' command:
--optimize (-O) optimization level: -O1 for "python -O", -O2 for
"python -OO", and -O0 to disable [default: -O0]
--dist-dir (-d) directory to put final built distributions in (default
is dist)
--excludes (-e) comma-separated list of modules to exclude
--dll-excludes comma-separated list of DLLs to exclude
--ignores comma-separated list of modules to ignore if they are
not found
--includes (-i) comma-separated list of modules to include
--packages (-p) comma-separated list of packages to include
--compressed (-c) create a compressed zipfile
--xref (-x) create and show a module cross reference
--bundle-files (-b) bundle dlls in the zipfile or the exe. Valid levels
are 1, 2, or 3 (default)
--skip-archive do not place Python bytecode files in an archive, put
them directly in the file system
--ascii (-a) do not automatically include encodings and codecs
--custom-boot-script Python file that will be run when setting up the
runtime environment
usage: screenshot_setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: screenshot_setup.py --help [cmd1 cmd2 ...]
or: screenshot_setup.py --help-commands
or: screenshot_setup.py cmd --help
E:\tmp\pyexe_tmp>
~~~
下一篇文章讲解如何使python源文件打包为windows服务。
- 前言
- Python:实现文件归档
- Pyhon:按行输出文件内容
- Python:读文件和写文件
- Python:实现一个小算法
- Python:通过命令行发送新浪微博
- Python:通过摄像头实现的监控功能
- Python:通过摄像头抓取图像并自动上传至新浪微博
- Python:简单的摄像头程序实现
- Python:日志模块logging的应用
- Python:操作嵌入式数据库SQLite
- Python:将句子中的单词全部倒排过来,但单词的字母顺序不变
- Python:语音处理,实现在线朗读RFC文档或本地文本文件
- Python:通过计算阶乘来学习lambda和reduce这两个函数的使用
- Python:通过执行100万次打印来比较C和python的性能,以及用C和python结合来解决性能问题的方法
- Python:使用matplotlib绘制图表
- Python:使用pycha快速绘制办公常用图(饼图、垂直直方图、水平直方图、散点图等七种图形)
- Python:使用pycha快速绘制办公常用图二(使用样式定制个性化图表)
- Python:监控键盘输入、鼠标操作,并将捕获到的信息记录到文件中
- Python:通过获取淘宝账号和密码的实验,来看登陆方式选择的重要性
- Python:通过获取淘宝账号和密码的实验,来看登陆方式选择的重要性(二)
- Python:通过远程监控用户输入来获取淘宝账号和密码的实验(一)
- Python:通过远程监控用户输入来获取淘宝账号和密码的实验(二)
- Python:通过自定义系统级快捷键来控制程序运行
- Python:通过自定义系统级快捷键来控制程序开始或停止记录日志(使用小技巧解决一个貌似无解的问题)
- Python:一个多功能的抓图工具开发(附源码)
- Python:程序发布方式简介一(打包为可执行文件EXE)
- Python:新浪微博应用开发简介(认证及授权部分)
- Python:程序最小化到托盘功能实现
- Python:实用抓图工具开发介绍(含需求分析、设计、编码、单元测试、打包、系统测试、发布各环节)
- Python:桌面气泡提示功能实现
- Python:未来三个月的python学习计划
- Python:pygame模块及SDL库简介
- Python:获取新浪微博用户的收听列表和粉丝列表
- Python:pygame游戏编程之旅一(Hello World)
- Python:pygame游戏编程之旅二(自由移动的小球)
- Python:pygame游戏编程之旅三(玩家控制的小球)
- Python:pygame游戏编程之旅四(游戏界面文字处理)
- Python:pygame游戏编程之旅五(游戏界面文字处理详解)
- Python:pygame游戏编程之旅六(游戏中的声音处理)
- Python:pygame游戏编程之旅七(pygame基础知识讲解1)
- Python:编程“八荣八耻”之我见
- Python:脚本的几种执行方式
- wxPython:简单的wxPython程序
- wxPython:简单的wxPython程序的另一种写法
- wxPython:应用程序对象介绍
- wxPython:输出重定向
- wxPython:关闭wxPython程序
- wxPython:Frame类介绍
- wxPython:面板Panel的使用
- wxPython:工具栏、状态栏、菜单实现
- wxPython:消息对话框MessageDialog
- wxPython:文本对话框TextEntryDialog
- wxPython:列表选择框SingleChoiceDialog
- wxPython:事件处理介绍一
- wxPython:事件处理介绍二
- wxPython: 简单的绘图例子
- wxPython:状态栏介绍
- wxPython:菜单介绍
- wxPython:文件对话框wx.FileDialog
- wxPython:颜色选择对话框wx.ColourDialog
- wxPython:布局管理器sizer介绍
- wxPython:启动画面SplashScreen介绍
- wxPython:绘画按钮BitmapButton介绍
- wxPython:进度条Gauge介绍
- Python: 发送新浪微博(使用oauth2)
- Python:读取新浪微博收听列表
- Python:DNS客户端实现