以上问题都在setup.py文件中解决!给出我的setup.py文件代码:
from distutils.core import setup import py2exe import sys import glob import os if len(sys.argv) == 1: sys.argv.append("py2exe") sys.argv.append("-q") class Target: def __init__(self, **kw): self.__dict__.update(kw) self.version = "1.0.0" self.company_name = "www.12366.net" self.copyright = "zr @2013" self.name = "pythonTax" data_files = [ ("imMainFrameImage", glob.glob(r'imMainFrameImage/*.png')#os.listdir('imMainFrameImage') ), ("mainFrameImage", glob.glob(r'mainFrameImage/*.png')#os.listdir('mainFrameImage') ) ] manifest = \ ''' <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <noInheritable></noInheritable> <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.30729.1" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"> </assemblyIdentity> <file name="msvcr90.dll" hashalg="SHA1" hash="9785b1c493deb5b2134dc4aef3719cee207001bc"> <asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> <dsig:Transforms> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"> </dsig:Transform> </dsig:Transforms> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"> </dsig:DigestMethod> <dsig:DigestValue>VF5ECUAHPV7EnUf+/UIXMPizPvs=</dsig:DigestValue> </asmv2:hash> </file> <file name="msvcp90.dll" hashalg="SHA1" hash="0f6bbf7fe4fb3fca2cb5b542eca1a1cad051f01c"> <asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> <dsig:Transforms> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform> </dsig:Transforms> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"> </dsig:DigestMethod> <dsig:DigestValue>3Wg+StVMq2uhx7POnAkl2w4dDmY=</dsig:DigestValue> </asmv2:hash> </file> <file name="msvcm90.dll" hashalg="SHA1" hash="7f3290ab2b7444c2b4a9b1fedfdb16466d7a21bb"> <asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> <dsig:Transforms> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"> </dsig:Transform> </dsig:Transforms> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"> </dsig:DigestMethod> <dsig:DigestValue>/YfRn7UQENzdMeoMHxTgdRMiObA=</dsig:DigestValue> </asmv2:hash> </file> <description>pythonTax</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 pythonTax = Target( description = "pythonTax", script = "main.py", other_resources = [(RT_MANIFEST, 1, manifest)], icon_resources = [(1, "snake.ico")], dest_base = "pythonTax") includes=["encodings","encodings.*"] options = {"py2exe":{"compressed": 1, "optimize": 2, "ascii": 1, "includes":includes, "packages": ["sqlalchemy.dialects.sqlite"], "bundle_files": 1 } } setup( options = options, zipfile=None, windows=[pythonTax], data_files=data_files )
其中includes语句指定py2exe需要打包的模块,这里就解决了1、2问题。剩下来的3、4问题的解决也在stup.py里面啦^_^
1.如果显示错误提示的话 ”msvcp90.dll: no such file or directory”,请尝试下面的方法:
2.如果遇到 ImportError: No module named sip 的错误,建议使用如下方法解决:
除了9.0.21022.8这个版本号的MSVCR90.DLL之外,我们还需要一个Microsoft.VC90.CRT.manifest文件放在同一目录下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <noInheritable></noInheritable> <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity> <file name="msvcr90.dll"/> </assembly>