py2exe打包笔记
iTip虽然已经打包成功,但是有两点遗憾,一是未能打包成单个exe文件,打包目录下零散文件太多;二是打包后窗体xp样式丢失@_@。今天,终于~~终于解决了!
先记录一下我打包遇到的问题:
- ImportError: No module named sqlite
- LookupError: unknown encoding: ascii
- 如何打包成单个exe文件
- 打包后窗口xp样式丢失
以上问题都在setup.py文件中解决!给出我的setup.py文件代码:
01# Requires wxPython. This sample demonstrates:
02#
03# - single file exe using wxPython as GUI.
04
05fromdistutils.coreimportsetup
06importpy2exe
07importsys
08
09# If run without args, build executables, in quiet mode.
10
11iflen(sys.argv)==1:
12sys.argv.append("py2exe")
13sys.argv.append("-q")
14
15classTarget:
16def__init__(self,**kw):
17self.__dict__.update(kw)
18# for the versioninfo resources
19self.version="1.0.0"
20self.company_name="www.xsmile.net"
21self.copyright="xsmile @2008"
22self.name="iTip"
23
24################################################################
25
26# A program using wxPython
27# The manifest will be inserted as resource into iTip.exe. <span style="color: #0000ff;">This</span>
28<span style="color: #0000ff;"># gives the controls the Windows XP appearance (ifrun on XP <img src="http://www.xsmile.net/wp-includes/images/smilies/icon_wink.gif"alt=";-)"class="wp-smiley"> </span>
29#
30# Another option would be to store it in a file named
31# iTip.exe.manifest, and copy it with the data_files option into
32# the dist-dir.
33#
34manifest_template='''
35<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
36<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
37<assemblyIdentity
38version="5.0.0.0"
39processorArchitecture="x86"
40name="%(prog)s"
41type="win32"
42/>
43<description>%(prog)s Program</description>
44<dependency>
45<dependentAssembly>
46<assemblyIdentity
47type="win32"
48name="Microsoft.Windows.Common-Controls"
49version="6.0.0.0"
50processorArchitecture="X86"
51publicKeyToken="6595b64144ccf1df"
52language="*"
53/>
54</dependentAssembly>
55</dependency>
56</assembly>
57
58'''
59
60RT_MANIFEST=24
61
62iTip=Target(
63# used for the versioninfo resource
64description="A ENote Application",
65# what to build
66script="iTip.py",
67
68other_resources=[(RT_MANIFEST,1, manifest_template%dict(prog="iTip"))],
69icon_resources=[(1,"iTip.ico")],
70dest_base="iTip")
71
72################################################################
73
74<span style="color: #0000ff;">includes=["encodings","encodings.*","sqlalchemy.databases.sqlite"]</span>
75setup(
76options={"py2exe": {"compressed":1,
77"optimize":2,
78"ascii":1,
79<span style="color: #0000ff;">"includes":includes,</span>
80"bundle_files":1}},
81zipfile=None,
82windows=[iTip],
83)
84
85############################################################其中includes语句指定py2exe需要打包的模块,这里就解决了1、2问题。剩下来的3、4问题的解决也在stup.py里面啦^_^
浙公网安备 33010602011771号