python3 使用py2exe打包exe

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





转载于:https://my.oschina.net/winds/blog/300478

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值