xsmile
You can fly higher
xsmile's Blog
py2exe打包笔记

iTip虽然已经打包成功,但是有两点遗憾,一是未能打包成单个exe文件,打包目录下零散文件太多;二是打包后窗体xp样式丢失@_@。今天,终于~~终于解决了!

先记录一下我打包遇到的问题:

  1. ImportError: No module named sqlite
  2. LookupError: unknown encoding: ascii
  3. 如何打包成单个exe文件
  4. 打包后窗口xp样式丢失

以上问题都在setup.py文件中解决!给出我的setup.py文件代码:

# Requires wxPython.  This sample demonstrates:
#
# - single file exe using wxPython as GUI.

from distutils.core import setup
import py2exe
import sys

# If run without args, build executables, in quiet mode.

if len(sys.argv) == 1:
sys.argv.append("py2exe")
sys.argv.append("-q")

class Target:
def __init__(self, **kw):
self.__dict__.update(kw)
# for the versioninfo resources
self.version = "1.0.0"
self.company_name = "www.xsmile.net"
self.copyright = "xsmile @2008"
self.name = "iTip"

################################################################

# A program using wxPython
# The manifest will be inserted as resource into iTip.exe.  This
# gives the controls the Windows XP appearance (if run on XP ;-)
#
# Another option would be to store it in a file named
# iTip.exe.manifest, and copy it with the data_files option into
# the dist-dir.
#
manifest_template = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="5.0.0.0"
processorArchitecture="x86"
name="%(prog)s"
type="win32"
/>
<description>%(prog)s Program</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>

'''

RT_MANIFEST = 24

iTip = Target(
# used for the versioninfo resource
description = "A ENote Application",
# what to build
script = "iTip.py",

other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="iTip"))],
icon_resources = [(1, "iTip.ico")],
dest_base = "iTip")

################################################################

includes=["encodings","encodings.*","sqlalchemy.databases.sqlite"]
setup(
options = {"py2exe": {"compressed": 1,
"optimize": 2,
"ascii": 1,
"includes":includes,
"bundle_files": 1}},
zipfile = None,
windows = [iTip],
)

############################################################
其中includes语句指定py2exe需要打包的模块,这里就解决了1、2问题。剩下来的3、4问题的解决也在stup.py里面啦^_^
首页      技术      Python      py2exe打包笔记

发表回复

textsms
account_circle
email

  • Jacky

    太感谢你啦,在使用SQLAlchemy打包时遇到同样类似的问题,解决啦。
    py2exe文档还是太少。
    谢谢。

    16 年前 回复
  • Felix

    博主帮忙,为啥我做的wxpython用py2exe打包后再别的机器上不能用?我的setup.py如下
    from distutils.core import setup
    import py2exe
    setup(options = {“py2exe”: {“compressed”: 1, “optimize”: 2, “ascii”: 1,
    “bundle_files”: 1}},
    zipfile = None, windows = [{“script”: “1_3_11.py”}],

    )

    16 年前 回复
  • xsmile

    如果不能正常运行,会在目录下生成一个错误日志文件。看看里面是什么内容呢?

    16 年前 回复

xsmile's Blog

py2exe打包笔记
iTip虽然已经打包成功,但是有两点遗憾,一是未能打包成单个exe文件,打包目录下零散文件太多;二是打包后窗体xp样式丢失@_@。今天,终于~~终于解决了! 先记录一下我打包遇到的问题: …
扫描二维码继续阅读
2008-11-22