py2exe在sourceforge 的下載只支持到2.7。python
針對python3.0+的版本,須要本身編譯。windows
svn checkout svn://svn.code.sf.net/p/py2exe/svn/trunk py2exe-svnapp
這裏使用的是vs2014.svn
進入py2exe-3ui
python setup.py installspa
這裏會進行編譯、安裝。.net
此外,python默認使用的是vs9,針對vs2014,須要改下文件:code
Lib\distutils\msvc9compiler.pyip
尋找:ci
VERSION = get_build_version()
在下面增長:
VERSION = 11.0
若是出現錯誤:
Failed to load and parse the manifest. The system cannot find the file specified.
error: command 'mt.exe' failed with exit status 31
解決辦法:因爲vs2010後的link.exe的參數稍微有些改變,因此在link的時候沒有生成manifest文件,天然mt.exe找不到這個文件。只須要在msvc9compiler.py裏面搜索一下MANIFESTFILE,而後在他上面加一行ld_args.append('/MANIFEST'),保存就OK了。(python3.4好像沒有這個問題,2.7存在)
setup.py能夠參考官網,其中的參數--bundle-files,須要特別說下,想打成一個整包要設成0.
變化能夠參考:http://sourceforge.net/p/py2exe/svn/HEAD/tree/trunk/py2exe-3/
最後附上setup.py
from distutils.core import setup import py2exe import sys,os if sys.version_info.major >= 3.0: opt_bundle_files = 0 else: opt_bundle_files = 1 includes = ["PyQt4.QtCore","PyQt4.QtGui","sip"] options = {"py2exe": { "compressed": 1, "optimize": 2, "includes": includes, "bundle_files": opt_bundle_files, } } setup( version = "0.1.0", description = "test_add", options = options, zipfile=None, console=[{"script": "test_add.py", "icon_resources": [(1, "py.ico")] }], #windows=[{"script": "test_add.py", "icon_resources": [(1, "py.ico")] }], )