Python是一个强大的工具,可惜不是每个人的计算机里面都有安装。当您写了一个好用的工具。要如何让那些没有安装Python的人使用你的工具呢?
对于这样一个需要standalone exectuable环境的需求,直到撰写经验为止,只看到两个比较好用且有持续维护的套件。一个是py2exe。另外一个就是本经验要介绍的PyInstaller。
工具/原料
PyInstaller
Python
PyInstaller安装
1
下载地址:http://www.pyinstaller.org/wiki
2
最新版本:PyInstaller 2.0
3
直接“解压缩”之后即可使用,解压到您想让他在的路径即可
END
PyInstaller配置
1
事先写好py程序
2
在命令行执行:python Makespec.py --console --onefile NotePad\notepad.py
报错:Configfile is missing or unreadable. Please run Configure.py before building
3
在命令行执行:Configure.py
报错:Python 2.6+ on Windows support needs pywin32,Please install http://sourceforge.net/projects/pywin32/
4
安装最新版本的 pywin32-217.win32-py2.7.exe,下载地址:http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/
END
PyInstaller使用
1
命令行中运行
2
目录切换到PyInstaller的安装目录“E:\pyinstaller-1.5\pyinstaller-1.5>”
3
在PyInstaller的安装目录下新建一个文件夹(比如NotePad), 然后将要转换的py脚本放到文件夹里(notepad.py)
4
E:\pyinstaller-1.5\pyinstaller-1.5>python Makespec.py --console --onefile NotePad\notepad.py
5
E:\pyinstaller-1.5\pyinstaller-1.5>python Build.py NotePad\notepad.spec
6
验证exeE:\pyinstaller-1.5\pyinstaller-1.5>
E:\pyinstaller-1.5\pyinstaller-1.5\NotePad\dist\notepad.exe 0 0 100(成功)
7
查看生成的文件,生成的中间文件spec
8
查看生成的文件,生成的最终文件exe
END
注意事项
在转换之前要确保py程序可以正常通过
如果转换过程中出现什么错误,用搜索引擎搜索解决一下
经验内容仅供参考,如果您需解决具体问题(尤其法律、医学等领域),建议您详细咨询相关领域专业人士。
举报作者声明:本篇经验系本人依照真实经历原创,未经许可,谢绝转载。
展开阅读全部