第一个wxPython及转化成exe(二)

s


http://blog.csdn.net/xtx1990/article/details/7185289


中文的问题

src下创建文件sitecustomize.py

import sys
reload(sys)
sys.setdefaultencoding('utf8')



在app.py中

# coding=utf-8

import sitecustomize

写文件用utf8,读取的中文更转成unicode

users = [unicode(x,'utf-8') for x in users]



*.py中硬编码用u'中文'


图标

        if os.path.exists("apiTest1.exe"):
            self.SetIcon(wx.Icon("apiTest1.exe", wx.BITMAP_TYPE_ICO))
        else:
            self.icon = wx.Icon('app.ico', wx.BITMAP_TYPE_ICO)
            self.SetIcon(self.icon) 

convert2exe.py

# coding=utf-8
from distutils.core import setup



import py2exe

#how to:
#cmd: python convert2exe.py py2exe
#cmd: upx -9 -f "app.exe"




#setup(windows=[{"script": "apiTest1.py"}])






includes = ["encodings", "encodings.*"]
options = {"py2exe":
            {   "compressed": True,
                "optimize": 2,
                "includes": includes,
                "bundle_files": 1
            }
          }
setup(   

    version = "0.1.0",
    description = "apiTest",
    name = "apiTest",
    options = options,
    zipfile=None,
    windows=[{"script": "apiTest1.py","icon_resources": [(1, "app.ico")]}],  
)





文件说明

MSVCR71.dll大部分机器都有

不在98下运行,那就不要w9xpopen.exe


压缩

4、压缩程序。程序体积有点大,用upx压缩一下,执行命令upx -9 -f "app.exe"

http://ftp.pconline.com.cn/3a0b46f13d6f99f8b1fa73847df01254/pub/download/201010/upx308w.zip

upx app.exe -o a.exe



s





你可能感兴趣的:(python)