设为首页 收藏本站
查看: 861|回复: 0

[经验分享] Python:程序发布方式简介一(打包为可执行文件EXE)

[复制链接]

尚未签到

发表于 2017-5-8 09:54:23 | 显示全部楼层 |阅读模式
   本文介绍如何使用py2exe来将python源程序打包成文件。以上一篇文章Python:一个多功能的抓图工具开发(附源码)中的源程序为例进行讲述。
   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:F68DE:.CameraDll.dllscreenshot.icoScreenshot.pyscreenshot_setup.py没有子文件夹E:\tmp\pyexe_tmp> b、执行打包脚本:E:\tmp\pyexe_tmp>python screenshot_setup.py py2exepython screenshot_setup.py py2exerunning py2execreating E:\tmp\pyexe_tmp\buildcreating E:\tmp\pyexe_tmp\build\bdist.win32creating E:\tmp\pyexe_tmp\build\bdist.win32\winexecreating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\bundle-2.6creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\tempcreating 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.pybyte-compiling C:\Python26\lib\StringIO.py to StringIO.pyobyte-compiling C:\Python26\lib\UserDict.py to UserDict.pyobyte-compiling C:\Python26\lib\__future__.py to __future__.pyobyte-compiling C:\Python26\lib\_abcoll.py to _abcoll.pyobyte-compiling C:\Python26\lib\_strptime.py to _strptime.pyobyte-compiling C:\Python26\lib\_threading_local.py to _threading_local.pyobyte-compiling C:\Python26\lib\abc.py to abc.pyobyte-compiling C:\Python26\lib\atexit.py to atexit.pyobyte-compiling C:\Python26\lib\base64.py to base64.pyobyte-compiling C:\Python26\lib\bdb.py to bdb.pyobyte-compiling C:\Python26\lib\bisect.py to bisect.pyobyte-compiling C:\Python26\lib\calendar.py to calendar.pyobyte-compiling C:\Python26\lib\cmd.py to cmd.pyobyte-compiling C:\Python26\lib\codecs.py to codecs.pyobyte-compiling C:\Python26\lib\collections.py to collections.pyobyte-compiling C:\Python26\lib\colorsys.py to colorsys.pyobyte-compiling C:\Python26\lib\copy.py to copy.pyobyte-compiling C:\Python26\lib\copy_reg.py to copy_reg.pyobyte-compiling C:\Python26\lib\ctypes\__init__.py to ctypes\__init__.pyobyte-compiling C:\Python26\lib\ctypes\_endian.py to ctypes\_endian.pyobyte-compiling C:\Python26\lib\ctypes\wintypes.py to ctypes\wintypes.pyobyte-compiling C:\Python26\lib\difflib.py to difflib.pyobyte-compiling C:\Python26\lib\dis.py to dis.pyobyte-compiling C:\Python26\lib\doctest.py to doctest.pyobyte-compiling C:\Python26\lib\dummy_thread.py to dummy_thread.pyobyte-compiling C:\Python26\lib\encodings\__init__.py to encodings\__init__.pyobyte-compiling C:\Python26\lib\encodings\aliases.py to encodings\aliases.pyobyte-compiling C:\Python26\lib\encodings\ascii.py to encodings\ascii.pyobyte-compiling C:\Python26\lib\encodings\base64_codec.py to encodings\base64_codec.pyobyte-compiling C:\Python26\lib\encodings\big5.py to encodings\big5.pyobyte-compiling C:\Python26\lib\encodings\big5hkscs.py to encodings\big5hkscs.pyobyte-compiling C:\Python26\lib\encodings\bz2_codec.py to encodings\bz2_codec.pyobyte-compiling C:\Python26\lib\encodings\charmap.py to encodings\charmap.pyobyte-compiling C:\Python26\lib\encodings\cp037.py to encodings\cp037.pyobyte-compiling C:\Python26\lib\encodings\cp1006.py to encodings\cp1006.pyobyte-compiling C:\Python26\lib\encodings\cp1026.py to encodings\cp1026.pyobyte-compiling C:\Python26\lib\encodings\cp1140.py to encodings\cp1140.pyobyte-compiling C:\Python26\lib\encodings\cp1250.py to encodings\cp1250.pyobyte-compiling C:\Python26\lib\encodings\cp1251.py to encodings\cp1251.pyobyte-compiling C:\Python26\lib\encodings\cp1252.py to encodings\cp1252.pyobyte-compiling C:\Python26\lib\encodings\cp1253.py to encodings\cp1253.pyobyte-compiling C:\Python26\lib\encodings\cp1254.py to encodings\cp1254.pyobyte-compiling C:\Python26\lib\encodings\cp1255.py to encodings\cp1255.pyobyte-compiling C:\Python26\lib\encodings\cp1256.py to encodings\cp1256.pyobyte-compiling C:\Python26\lib\encodings\cp1257.py to encodings\cp1257.pyobyte-compiling C:\Python26\lib\encodings\cp1258.py to encodings\cp1258.pyobyte-compiling C:\Python26\lib\encodings\cp424.py to encodings\cp424.pyobyte-compiling C:\Python26\lib\encodings\cp437.py to encodings\cp437.pyobyte-compiling C:\Python26\lib\encodings\cp500.py to encodings\cp500.pyobyte-compiling C:\Python26\lib\encodings\cp737.py to encodings\cp737.pyobyte-compiling C:\Python26\lib\encodings\cp775.py to encodings\cp775.pyobyte-compiling C:\Python26\lib\encodings\cp850.py to encodings\cp850.pyobyte-compiling C:\Python26\lib\encodings\cp852.py to encodings\cp852.pyobyte-compiling C:\Python26\lib\encodings\cp855.py to encodings\cp855.pyobyte-compiling C:\Python26\lib\encodings\cp856.py to encodings\cp856.pyobyte-compiling C:\Python26\lib\encodings\cp857.py to encodings\cp857.pyobyte-compiling C:\Python26\lib\encodings\cp860.py to encodings\cp860.pyobyte-compiling C:\Python26\lib\encodings\cp861.py to encodings\cp861.pyobyte-compiling C:\Python26\lib\encodings\cp862.py to encodings\cp862.pyobyte-compiling C:\Python26\lib\encodings\cp863.py to encodings\cp863.pyobyte-compiling C:\Python26\lib\encodings\cp864.py to encodings\cp864.pyobyte-compiling C:\Python26\lib\encodings\cp865.py to encodings\cp865.pyobyte-compiling C:\Python26\lib\encodings\cp866.py to encodings\cp866.pyobyte-compiling C:\Python26\lib\encodings\cp869.py to encodings\cp869.pyobyte-compiling C:\Python26\lib\encodings\cp874.py to encodings\cp874.pyobyte-compiling C:\Python26\lib\encodings\cp875.py to encodings\cp875.pyobyte-compiling C:\Python26\lib\encodings\cp932.py to encodings\cp932.pyobyte-compiling C:\Python26\lib\encodings\cp949.py to encodings\cp949.pyobyte-compiling C:\Python26\lib\encodings\cp950.py to encodings\cp950.pyobyte-compiling C:\Python26\lib\encodings\euc_jis_2004.py to encodings\euc_jis_2004.pyobyte-compiling C:\Python26\lib\encodings\euc_jisx0213.py to encodings\euc_jisx0213.pyobyte-compiling C:\Python26\lib\encodings\euc_jp.py to encodings\euc_jp.pyobyte-compiling C:\Python26\lib\encodings\euc_kr.py to encodings\euc_kr.pyobyte-compiling C:\Python26\lib\encodings\gb18030.py to encodings\gb18030.pyobyte-compiling C:\Python26\lib\encodings\gb2312.py to encodings\gb2312.pyobyte-compiling C:\Python26\lib\encodings\gbk.py to encodings\gbk.pyobyte-compiling C:\Python26\lib\encodings\hex_codec.py to encodings\hex_codec.pyobyte-compiling C:\Python26\lib\encodings\hp_roman8.py to encodings\hp_roman8.pyobyte-compiling C:\Python26\lib\encodings\hz.py to encodings\hz.pyobyte-compiling C:\Python26\lib\encodings\idna.py to encodings\idna.pyobyte-compiling C:\Python26\lib\encodings\iso2022_jp.py to encodings\iso2022_jp.pyobyte-compiling C:\Python26\lib\encodings\iso2022_jp_1.py to encodings\iso2022_jp_1.pyobyte-compiling C:\Python26\lib\encodings\iso2022_jp_2.py to encodings\iso2022_jp_2.pyobyte-compiling C:\Python26\lib\encodings\iso2022_jp_2004.py to encodings\iso2022_jp_2004.pyobyte-compiling C:\Python26\lib\encodings\iso2022_jp_3.py to encodings\iso2022_jp_3.pyobyte-compiling C:\Python26\lib\encodings\iso2022_jp_ext.py to encodings\iso2022_jp_ext.pyobyte-compiling C:\Python26\lib\encodings\iso2022_kr.py to encodings\iso2022_kr.pyobyte-compiling C:\Python26\lib\encodings\iso8859_1.py to encodings\iso8859_1.pyobyte-compiling C:\Python26\lib\encodings\iso8859_10.py to encodings\iso8859_10.pyobyte-compiling C:\Python26\lib\encodings\iso8859_11.py to encodings\iso8859_11.pyobyte-compiling C:\Python26\lib\encodings\iso8859_13.py to encodings\iso8859_13.pyobyte-compiling C:\Python26\lib\encodings\iso8859_14.py to encodings\iso8859_14.pyobyte-compiling C:\Python26\lib\encodings\iso8859_15.py to encodings\iso8859_15.pyobyte-compiling C:\Python26\lib\encodings\iso8859_16.py to encodings\iso8859_16.pyobyte-compiling C:\Python26\lib\encodings\iso8859_2.py to encodings\iso8859_2.pyobyte-compiling C:\Python26\lib\encodings\iso8859_3.py to encodings\iso8859_3.pyobyte-compiling C:\Python26\lib\encodings\iso8859_4.py to encodings\iso8859_4.pyobyte-compiling C:\Python26\lib\encodings\iso8859_5.py to encodings\iso8859_5.pyobyte-compiling C:\Python26\lib\encodings\iso8859_6.py to encodings\iso8859_6.pyobyte-compiling C:\Python26\lib\encodings\iso8859_7.py to encodings\iso8859_7.pyobyte-compiling C:\Python26\lib\encodings\iso8859_8.py to encodings\iso8859_8.pyobyte-compiling C:\Python26\lib\encodings\iso8859_9.py to encodings\iso8859_9.pyobyte-compiling C:\Python26\lib\encodings\johab.py to encodings\johab.pyobyte-compiling C:\Python26\lib\encodings\koi8_r.py to encodings\koi8_r.pyobyte-compiling C:\Python26\lib\encodings\koi8_u.py to encodings\koi8_u.pyobyte-compiling C:\Python26\lib\encodings\latin_1.py to encodings\latin_1.pyobyte-compiling C:\Python26\lib\encodings\mac_arabic.py to encodings\mac_arabic.pyobyte-compiling C:\Python26\lib\encodings\mac_centeuro.py to encodings\mac_centeuro.pyobyte-compiling C:\Python26\lib\encodings\mac_croatian.py to encodings\mac_croatian.pyobyte-compiling C:\Python26\lib\encodings\mac_cyrillic.py to encodings\mac_cyrillic.pyobyte-compiling C:\Python26\lib\encodings\mac_farsi.py to encodings\mac_farsi.pyobyte-compiling C:\Python26\lib\encodings\mac_greek.py to encodings\mac_greek.pyobyte-compiling C:\Python26\lib\encodings\mac_iceland.py to encodings\mac_iceland.pyobyte-compiling C:\Python26\lib\encodings\mac_latin2.py to encodings\mac_latin2.pyobyte-compiling C:\Python26\lib\encodings\mac_roman.py to encodings\mac_roman.pyobyte-compiling C:\Python26\lib\encodings\mac_romanian.py to encodings\mac_romanian.pyobyte-compiling C:\Python26\lib\encodings\mac_turkish.py to encodings\mac_turkish.pyobyte-compiling C:\Python26\lib\encodings\mbcs.py to encodings\mbcs.pyobyte-compiling C:\Python26\lib\encodings\palmos.py to encodings\palmos.pyobyte-compiling C:\Python26\lib\encodings\ptcp154.py to encodings\ptcp154.pyobyte-compiling C:\Python26\lib\encodings\punycode.py to encodings\punycode.pyobyte-compiling C:\Python26\lib\encodings\quopri_codec.py to encodings\quopri_codec.pyobyte-compiling C:\Python26\lib\encodings\raw_unicode_escape.py to encodings\raw_unicode_escape.pyobyte-compiling C:\Python26\lib\encodings\rot_13.py to encodings\rot_13.pyobyte-compiling C:\Python26\lib\encodings\shift_jis.py to encodings\shift_jis.pyobyte-compiling C:\Python26\lib\encodings\shift_jis_2004.py to encodings\shift_jis_2004.pyobyte-compiling C:\Python26\lib\encodings\shift_jisx0213.py to encodings\shift_jisx0213.pyobyte-compiling C:\Python26\lib\encodings\string_escape.py to encodings\string_escape.pyobyte-compiling C:\Python26\lib\encodings\tis_620.py to encodings\tis_620.pyobyte-compiling C:\Python26\lib\encodings\undefined.py to encodings\undefined.pyobyte-compiling C:\Python26\lib\encodings\unicode_escape.py to encodings\unicode_escape.pyobyte-compiling C:\Python26\lib\encodings\unicode_internal.py to encodings\unicode_internal.pyobyte-compiling C:\Python26\lib\encodings\utf_16.py to encodings\utf_16.pyobyte-compiling C:\Python26\lib\encodings\utf_16_be.py to encodings\utf_16_be.pyobyte-compiling C:\Python26\lib\encodings\utf_16_le.py to encodings\utf_16_le.pyobyte-compiling C:\Python26\lib\encodings\utf_32.py to encodings\utf_32.pyobyte-compiling C:\Python26\lib\encodings\utf_32_be.py to encodings\utf_32_be.pyobyte-compiling C:\Python26\lib\encodings\utf_32_le.py to encodings\utf_32_le.pyobyte-compiling C:\Python26\lib\encodings\utf_7.py to encodings\utf_7.pyobyte-compiling C:\Python26\lib\encodings\utf_8.py to encodings\utf_8.pyobyte-compiling C:\Python26\lib\encodings\utf_8_sig.py to encodings\utf_8_sig.pyobyte-compiling C:\Python26\lib\encodings\uu_codec.py to encodings\uu_codec.pyobyte-compiling C:\Python26\lib\encodings\zlib_codec.py to encodings\zlib_codec.pyobyte-compiling C:\Python26\lib\functools.py to functools.pyobyte-compiling C:\Python26\lib\genericpath.py to genericpath.pyobyte-compiling C:\Python26\lib\getopt.py to getopt.pyobyte-compiling C:\Python26\lib\gettext.py to gettext.pyobyte-compiling C:\Python26\lib\heapq.py to heapq.pyobyte-compiling C:\Python26\lib\inspect.py to inspect.pyobyte-compiling C:\Python26\lib\keyword.py to keyword.pyobyte-compiling C:\Python26\lib\linecache.py to linecache.pyobyte-compiling C:\Python26\lib\locale.py to locale.pyobyte-compiling C:\Python26\lib\new.py to new.pyobyte-compiling C:\Python26\lib\ntpath.py to ntpath.pyobyte-compiling C:\Python26\lib\opcode.py to opcode.pyobyte-compiling C:\Python26\lib\optparse.py to optparse.pyobyte-compiling C:\Python26\lib\os.py to os.pyobyte-compiling C:\Python26\lib\os2emxpath.py to os2emxpath.pyobyte-compiling C:\Python26\lib\pdb.py to pdb.pyobyte-compiling C:\Python26\lib\pickle.py to pickle.pyobyte-compiling C:\Python26\lib\posixpath.py to posixpath.pyobyte-compiling C:\Python26\lib\pprint.py to pprint.pyobyte-compiling C:\Python26\lib\pyhk.py to pyhk.pyobyte-compiling C:\Python26\lib\quopri.py to quopri.pyobyte-compiling C:\Python26\lib\random.py to random.pyobyte-compiling C:\Python26\lib\re.py to re.pyobyte-compiling C:\Python26\lib\repr.py to repr.pyobyte-compiling C:\Python26\lib\shlex.py to shlex.pyobyte-compiling C:\Python26\lib\site-packages\PIL\BmpImagePlugin.py to PIL\BmpImagePlugin.pyobyte-compiling C:\Python26\lib\site-packages\PIL\GifImagePlugin.py to PIL\GifImagePlugin.pyobyte-compiling C:\Python26\lib\site-packages\PIL\GimpGradientFile.py to PIL\GimpGradientFile.pyobyte-compiling C:\Python26\lib\site-packages\PIL\GimpPaletteFile.py to PIL\GimpPaletteFile.pyobyte-compiling C:\Python26\lib\site-packages\PIL\Image.py to PIL\Image.pyobyte-compiling C:\Python26\lib\site-packages\PIL\ImageChops.py to PIL\ImageChops.pyobyte-compiling C:\Python26\lib\site-packages\PIL\ImageColor.py to PIL\ImageColor.pyobyte-compiling C:\Python26\lib\site-packages\PIL\ImageFile.py to PIL\ImageFile.pyobyte-compiling C:\Python26\lib\site-packages\PIL\ImageGrab.py to PIL\ImageGrab.pyobyte-compiling C:\Python26\lib\site-packages\PIL\ImageMode.py to PIL\ImageMode.pyobyte-compiling C:\Python26\lib\site-packages\PIL\ImagePalette.py to PIL\ImagePalette.pyobyte-compiling C:\Python26\lib\site-packages\PIL\ImageShow.py to PIL\ImageShow.pyobyte-compiling C:\Python26\lib\site-packages\PIL\JpegImagePlugin.py to PIL\JpegImagePlugin.pyobyte-compiling C:\Python26\lib\site-packages\PIL\PaletteFile.py to PIL\PaletteFile.pyobyte-compiling C:\Python26\lib\site-packages\PIL\PngImagePlugin.py to PIL\PngImagePlugin.pyobyte-compiling C:\Python26\lib\site-packages\PIL\PpmImagePlugin.py to PIL\PpmImagePlugin.pyobyte-compiling C:\Python26\lib\site-packages\PIL\TiffImagePlugin.py to PIL\TiffImagePlugin.pyobyte-compiling C:\Python26\lib\site-packages\PIL\TiffTags.py to PIL\TiffTags.pyobyte-compiling C:\Python26\lib\site-packages\PIL\__init__.py to PIL\__init__.pyobyte-compiling C:\Python26\lib\site-packages\pyHook\HookManager.py to pyHook\HookManager.pyobyte-compiling C:\Python26\lib\site-packages\pyHook\__init__.py to pyHook\__init__.pyobyte-compiling C:\Python26\lib\site-packages\pyHook\cpyHook.py to pyHook\cpyHook.pyobyte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py to wx\__init__.pyobyte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\__version__.py to wx\__version__.pyobyte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py to wx\_controls.pyobyte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py to wx\_core.pyobyte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py to wx\_gdi.pyobyte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py to wx\_misc.pyobyte-compiling C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py to wx\_windows.pyobyte-compiling C:\Python26\lib\site-packages\zipextimporter.py to zipextimporter.pyobyte-compiling C:\Python26\lib\sre.py to sre.pyobyte-compiling C:\Python26\lib\sre_compile.py to sre_compile.pyobyte-compiling C:\Python26\lib\sre_constants.py to sre_constants.pyobyte-compiling C:\Python26\lib\sre_parse.py to sre_parse.pyobyte-compiling C:\Python26\lib\stat.py to stat.pyobyte-compiling C:\Python26\lib\string.py to string.pyobyte-compiling C:\Python26\lib\stringprep.py to stringprep.pyobyte-compiling C:\Python26\lib\struct.py to struct.pyobyte-compiling C:\Python26\lib\subprocess.py to subprocess.pyobyte-compiling C:\Python26\lib\tempfile.py to tempfile.pyobyte-compiling C:\Python26\lib\textwrap.py to textwrap.pyobyte-compiling C:\Python26\lib\threading.py to threading.pyobyte-compiling C:\Python26\lib\token.py to token.pyobyte-compiling C:\Python26\lib\tokenize.py to tokenize.pyobyte-compiling C:\Python26\lib\traceback.py to traceback.pyobyte-compiling C:\Python26\lib\types.py to types.pyobyte-compiling C:\Python26\lib\unittest.py to unittest.pyobyte-compiling C:\Python26\lib\warnings.py to warnings.pyoC:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecatedimport setsremoving e:\tmp\tmp1ecbcw.py*** copy extensions ***copying C:\Python26\DLLs\_ctypes.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6copying C:\Python26\DLLs\bz2.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6copying C:\Python26\DLLs\select.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6copying C:\Python26\DLLs\unicodedata.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6copying C:\Python26\lib\site-packages\PIL\_imaging.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\PILcopying C:\Python26\lib\site-packages\pyHook\_cpyHook.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\pyHookcopying C:\Python26\lib\site-packages\win32\_win32sysloader.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6copying C:\Python26\lib\site-packages\win32\win32gui.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6copying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_controls_.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\wxcopying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core_.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\wxcopying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi_.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\wxcopying C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_misc_.pyd -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6\wxcopying 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.6setting 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.6copying C:\WINDOWS\system32\pythoncom26.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6copying C:\WINDOWS\system32\pywintypes26.dll -> E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6copying 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.6copying C:\Python26\w9xpopen.exe -> E:\tmp\pyexe_tmp\distcopying 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.6copying 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.6copying 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\distcopying C:\Python26\lib\site-packages\py2exe\run.exe -> E:\tmp\pyexe_tmp\dist\Screenshot.exeAdding python26.dll as resource to E:\tmp\pyexe_tmp\dist\Screenshot.exeThe 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, andmake sure you don't distribute files belonging to the operating system.OLEAUT32.dll - C:\WINDOWS\system32\OLEAUT32.dllUSER32.dll - C:\WINDOWS\system32\USER32.dllSHELL32.dll - C:\WINDOWS\system32\SHELL32.dllole32.dll - C:\WINDOWS\system32\ole32.dllCOMDLG32.dll - C:\WINDOWS\system32\COMDLG32.dllWSOCK32.dll - C:\WINDOWS\system32\WSOCK32.dllCOMCTL32.dll - C:\WINDOWS\system32\COMCTL32.dllWINMM.dll - C:\WINDOWS\system32\WINMM.dllmsvcrt.dll - C:\WINDOWS\system32\msvcrt.dllADVAPI32.dll - C:\WINDOWS\system32\ADVAPI32.dllGDI32.dll - C:\WINDOWS\system32\GDI32.dllRPCRT4.dll - C:\WINDOWS\system32\RPCRT4.dllKERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dllgdiplus.dll - C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\gdiplus.dllMSVCP90.dll - C:\WINDOWS\system32\MSVCP90.dllC:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecatedimport setswarning: 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:F68DE:.│  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└─distCameraDll.dllRCXBC.tmpScreenshot.exew9xpopen.exeE:\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/
  
from distutils.core import setupimport py2exeincludes = []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 py2exeC:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecatedimport setsCommon commands: (see '--help-commands' for more)setup.py build      will build the package underneath 'build/'setup.py install    will install the packageGlobal 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 messageOptions 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 (defaultis 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 arenot 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 levelsare 1, 2, or 3 (default)--skip-archive        do not place Python bytecode files in an archive, putthem 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 theruntime environmentusage: screenshot_setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]or: screenshot_setup.py --help [cmd1 cmd2 ...]or: screenshot_setup.py --help-commandsor: screenshot_setup.py cmd --helpE:\tmp\pyexe_tmp>
下一篇文章讲解如何使python源文件打包为windows服务。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-374511-1-1.html 上篇帖子: [Python]网络爬虫(八):糗事百科的网络爬虫(v0.2)源码及解析 下篇帖子: 机器学习算法与Python实践之(四)支持向量机(SVM)实现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表