Windows下用py2exe将Python程序打包成exe程序的教程
作者:goldensun 时间:2021-07-11 23:03:17
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")] }],
)
标签:Python,exe
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
初学者学习Python好还是Java好
2021-03-16 21:48:32
在FLASH中调用ASP的方法
2009-03-09 18:32:00
在PyCharm下使用 ipython 交互式编程的方法
2021-05-06 11:12:01
TensorFlow实现RNN循环神经网络
2023-03-18 18:12:49
![](https://img.aspxhome.com/file/2023/3/118393_0s.png)
Python趣味挑战之用pygame实现飞机塔防游戏
2022-07-18 04:00:02
![](https://img.aspxhome.com/file/2023/7/95867_0s.gif)
这些CSS Selector,你都熟悉吗?
2008-12-21 16:30:00
Python DPED机器学习之实现照片美化
2023-11-25 01:50:24
![](https://img.aspxhome.com/file/2023/5/86315_0s.jpg)
python函数运行内存时间等性能检测工具
2021-04-08 02:24:00
![](https://img.aspxhome.com/file/2023/1/93801_0s.png)
python多线程socket编程之多客户端接入
2021-01-26 10:14:52
![](https://img.aspxhome.com/file/2023/4/69054_0s.png)
python 一篇文章搞懂装饰器所有用法(建议收藏)
2023-12-06 17:27:43
![](https://img.aspxhome.com/file/2023/5/114535_0s.jpg)
企业网站FLASH引导页存在的意义
2008-06-04 11:09:00
SQL查询效率-100w数据查询只要1秒
2008-08-20 18:25:00
网站重构 CSS样式表的优化技巧
2009-05-12 11:51:00
asp下用OracleInProcServer完成对Oracle的连接和操作
2008-04-13 07:10:00
ASP模拟MVC模型的编程方式
2008-10-15 14:51:00
通过python下载FTP上的文件夹的实现代码
2022-03-16 11:19:12
科学设计你的网站网页
2008-03-16 13:48:00
显示某日期所在星期的所有日期asp代码
2008-06-01 16:05:00
TOPI如何使TVM代码不那么样板化
2022-02-02 00:22:07
Python判断一个三位数是否为水仙花数的示例
2021-11-06 06:14:13