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

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

一、简述

        记--将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.1 https://www.cnpython.com/pypi/pywin32-ctypes/downloadpywin32-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.4 altgraph:https://pypi.org/simple/altgraph/

下载pyinstaller包:Downloads — PyInstaller bundles Python applicationshttp://www.pyinstaller.org/downloads.htmlDownloads — PyInstaller bundles Python applications

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值