您当前的位置:首页 > 计算机 > 编程开发 > Python

Python 程序打包为exe可执行文件

时间:03-17来源:作者:点击数:

一、简述

记--将python程序打包为exe可执行程序,以便在其它没有安装python环境的电脑运行。

二、安装pyinstaller

打开cmd命令窗口,到python安装路径,输入pip.exe install pyinstaller

安装成功后执行:pyinstaller.exe -v查看版本信息。

如果不知道python安装路径,可以使用以下方式查看:

三、打包为exe可执行程序

打包命令:pyinstaller -F test.py

(-F参数指定生成独立的可执行文件,简单来说是一个exe,不加该参数就有动态库)

其中test.py是测试程序:

with open("test.txt", "w") as testFile:
    testFile.write("pack python to exe.\r\n")

print("finish!\r\n")
input("请按任意健继续...");

打包成功:

运行exe效果:

1、如果提示找不到pip.exe, pyinstaller.exe

请使用绝对路径或将exe所在路径添加到环境变量中。

比如例子中将C:\Users\Liang\AppData\Local\Programs\Python\Python38\Scripts\添加到环境变量。

2、离线安装pyinstaller

下载并安装各种依赖库:解压后到解压目录执行cmd命令:python setup.py install

2.1pywin32-ctypes:https://www.cnpython.com/pypi/pywin32-ctypes/download(exe就直接安装)

2.2 future:https://pypi.org/simple/future/

2.3 pefile:https://pypi.org/simple/pefile/

2.4altgraph:https://pypi.org/simple/altgraph/

下载pyinstaller包:Downloads — PyInstaller bundles Python applications

解压后到解压目录执行cmd命令:python setup.py install

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门