python转成exe_【Python】.py程序转换成.exe可执行程序

Python是一个强大的工具,可惜不是每个人的计算机里面都有安装。当您写了一个好用的工具。要如何让那些没有安装Python的人使用你的工具呢?

对于这样一个需要standalone exectuable环境的需求,直到撰写经验为止,只看到两个比较好用且有持续维护的套件。一个是py2exe。另外一个就是本经验要介绍的PyInstaller。

4e168d5653bbf820744c00bfba21056105a36e0f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

工具/原料

PyInstaller

Python

PyInstaller安装

1

下载地址:http://www.pyinstaller.org/wiki

b666b2530688912ccc7d4a5c1b4800fc76f7970f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

2

最新版本:PyInstaller 2.0

5e9a2820b93acd895572b0bb0335dd8a58de8b0f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

3

直接“解压缩”之后即可使用,解压到您想让他在的路径即可

c6b994775ddd884c6dfdb9936cef28066a01f60f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

END

PyInstaller配置

1

事先写好py程序

256eb672941fbee4ad6d66eac1237971ff1de70f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

2

在命令行执行:python Makespec.py --console --onefile NotePad\notepad.py

报错:Configfile is missing or unreadable. Please run Configure.py before building

586bfdefe0781431c301a4d8dc6699cf0353620f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

3

在命令行执行:Configure.py

报错:Python 2.6+ on Windows support needs pywin32,Please install http://sourceforge.net/projects/pywin32/

031231632385e036c626d15cb8e039723c035a0f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

4

安装最新版本的 pywin32-217.win32-py2.7.exe,下载地址:http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/

6061b9cd0c6efbf2a604e363127bbbf4db58da0f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

END

PyInstaller使用

1

命令行中运行

df087f0f8b56ad0480df815ddae10ef85956d00f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

2

目录切换到PyInstaller的安装目录“E:\pyinstaller-1.5\pyinstaller-1.5>”

d47cb624d8e9ccd20cd1c7ed0e40102a05e2c90f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

3

在PyInstaller的安装目录下新建一个文件夹(比如NotePad), 然后将要转换的py脚本放到文件夹里(notepad.py)

05a320a23a42a07a1fa72a87673834bb18efc10f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

4

E:\pyinstaller-1.5\pyinstaller-1.5>python Makespec.py --console --onefile NotePad\notepad.py

bd72f23834bb19ef66e89aa0497bd28287893a0c.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

5

E:\pyinstaller-1.5\pyinstaller-1.5>python Build.py NotePad\notepad.spec

c33acc828689a1467d06784df4bd4c7c35b3340c.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

6

验证exeE:\pyinstaller-1.5\pyinstaller-1.5>

E:\pyinstaller-1.5\pyinstaller-1.5\NotePad\dist\notepad.exe 0 0 100(成功)

4d3d2ab33c4133ba02f695c96a37c97623bc2f0c.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

7

查看生成的文件,生成的中间文件spec

3c42a5ea3e8630484df44160c33104ebf7a7520f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

8

查看生成的文件,生成的最终文件exe

05aae8a75f0f822b47598a86c018512c8df14d0f.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1

END

注意事项

在转换之前要确保py程序可以正常通过

如果转换过程中出现什么错误,用搜索引擎搜索解决一下

经验内容仅供参考,如果您需解决具体问题(尤其法律、医学等领域),建议您详细咨询相关领域专业人士。

举报作者声明:本篇经验系本人依照真实经历原创,未经许可,谢绝转载。

展开阅读全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值