使用py2exe將python3程序打包成exe

jopen 10年前發布 | 55K 次閱讀 py2exe Python開發

py2exe在sourceforge 的下載只支持到2.7。

針對python3.0+的版本,需要自己編譯。

1.下載源碼

svn checkout svn://svn.code.sf.net/p/py2exe/svn/trunk py2exe-svn

2.編譯環境

這里使用的是vs2014.

3.安裝

進入py2exe-3

python setup.py install

這里會進行編譯、安裝。

此外,python默認使用的是vs9,針對vs2014,需要改下文件:

Lib\distutils\msvc9compiler.py

尋找:

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存在)

4.setup.py

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")] }],

)</pre>來自:http://my.oschina.net/winds/blog/300478

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!