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

作者:清风拂面 | 创建时间: 2023-05-14
Python是一个强大的工具,可惜不是每个人的计算机里面都有安装。当您写了一个好用的工具。要如何让那些没有安装Python的人使用你的工具呢? 对于这样一个需要standalone exectuable环境的需求,直到撰写为止,只看到两个比...
【Python】.py程序转换成.exe可执行程序

PyInstaller安装

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

最新版本:PyInstaller 2.0

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

PyInstaller配置

事先写好py程序

在命令行执行:python Makespec.py --console --onefile NotePad\notepad.py 报错:Configfile is missing or unreadable. Please run Configure.py before building

在命令行执行:Configure.py 报错:Python 2.6+ on Windows support needs pywin32,Please install http://sourceforge.net/projects/pywin32/

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

PyInstaller使用

命令行中运行

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

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

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

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

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

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

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

温馨提示

在转换之前要确保py程序可以正常通过
如果转换过程中出现什么错误,用搜索引擎搜索解决一下
点击展开全文

更多推荐