Py2exe 打包后图标不显示

下载Png2Ico 

http://www.winterdrache.de/freeware/png2ico/

编辑图标大小准备 248*248 128*128 64*64 48*48 32*32 16*16的图标

命令下执行 Png2Icon.exe Attach.ico logo248.png logo128.png,logo64.png logo48.png logo32.png logo16.png 

生成Ico文件 这样就能适应win7下面的大小了。

如果程序需要管理员身份运行,在mainfest中 添加

[html]  view plain copy
  1.  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">  
  2.         <security>  
  3.           <requestedPrivileges>  
  4.             <requestedExecutionLevel level="requireAdministrator"   uiAccess="false"/>  
  5.           </requestedPrivileges>  
  6.         </security>  
  7. </trustInfo>  

下面是我的完整打包代码

注意修改版本号为version="9.0.21022.8"

[python]  view plain copy
  1. # -*- coding:gbk -*-  
  2. from distutils.core import  setup  
  3. from glob import glob  
  4. try:  
  5.     # py2exe 0.6.4 introduced a replacement modulefinder.  
  6.     # This means we have to add package paths there, not to the built-in  
  7.     # one.  If this new modulefinder gets integrated into Python, then  
  8.     # we might be able to revert this some day.  
  9.     # if this doesn't work, try import modulefinder  
  10.     try:  
  11.         import py2exe.mf as modulefinder  
  12.     except ImportError:  
  13.         import modulefinder  
  14.     import win32com, sys  
  15.   
  16.     for p in win32com.__path__[1:]:  
  17.         modulefinder.AddPackagePath("win32com", p)  
  18.     for extra in ["win32com.shell"]: #,"win32com.mapi"  
  19.         __import__(extra)  
  20.         m = sys.modules[extra]  
  21.         for p in m.__path__[1:]:  
  22.             modulefinder.AddPackagePath(extra, p)  
  23. except ImportError:  
  24.     # no build path setup, no worries.  
  25.     pass  
  26.   
  27. manifest = """ 
  28. <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
  29. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  30.     <noInheritable></noInheritable> 
  31.     <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"> 
  32.     </assemblyIdentity> 
  33.     <file name="msvcr90.dll" hashalg="SHA1" hash="9785b1c493deb5b2134dc4aef3719cee207001bc"> 
  34.     <asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> 
  35.     <dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"> 
  36.     </dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"> 
  37.     </dsig:DigestMethod><dsig:DigestValue>VF5ECUAHPV7EnUf+/UIXMPizPvs=</dsig:DigestValue></asmv2:hash> 
  38.     </file> 
  39.     <file name="msvcp90.dll" hashalg="SHA1" hash="0f6bbf7fe4fb3fca2cb5b542eca1a1cad051f01c"> 
  40.     <asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> 
  41.     <dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform> 
  42.     </dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"> 
  43.     </dsig:DigestMethod><dsig:DigestValue>3Wg+StVMq2uhx7POnAkl2w4dDmY=</dsig:DigestValue></asmv2:hash> 
  44.     </file> 
  45.     <file name="msvcm90.dll" hashalg="SHA1" hash="7f3290ab2b7444c2b4a9b1fedfdb16466d7a21bb"> 
  46.     <asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> 
  47.     <dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"> 
  48.     </dsig:Transform> 
  49.     </dsig:Transforms> 
  50.     <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"> 
  51.     </dsig:DigestMethod><dsig:DigestValue>/YfRn7UQENzdMeoMHxTgdRMiObA=</dsig:DigestValue></asmv2:hash> 
  52.     </file> 
  53.     <description>ETimes SafeDocument </description> 
  54.     <dependency> 
  55.         <dependentAssembly> 
  56.           <assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*' /> 
  57.         </dependentAssembly> 
  58.         </dependency> 
  59.         <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> 
  60.         <security> 
  61.           <requestedPrivileges> 
  62.             <requestedExecutionLevel level="requireAdministrator"   uiAccess="false"/> 
  63.           </requestedPrivileges> 
  64.         </security> 
  65.     </trustInfo> 
  66. </assembly> 
  67. """  
  68.   
  69. data_files = [("Microsoft.VC90.CRT",  
  70.                glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*'))]  
  71. py2exe_options = {"py2exe": {  
  72.     "compressed"1,  
  73.     "optimize"0,  
  74.     "bundle_files"1,  
  75.     "dll_excludes": ["mswsock.dll""powrprof.dll"],  
  76.     "excludes": ["email""System""clr"],  
  77.     "typelibs": [("{A435DD76-804E-4475-8FAB-986EACD1C6BE}"0x010), ]  
  78. }  
  79. }  
  80. setup(  
  81.     data_files=data_files,  
  82.     windows=[{  
  83.         'script''EtimesDocument.pyw',  
  84.         "other_resources":[(24,1,manifest)],  
  85.         "icon_resources": [  
  86.             (0'./png/Attach.ico')  
  87.         ]}],  
  88.     zipfile='core.lib',  
  89.     options=py2exe_options  
  90. )  
转载地址:http://blog.csdn.net/xugangjava/article/details/8049224

你可能感兴趣的:(Py2exe 打包后图标不显示)