栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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.rn")

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

打包成功:

运行exe效果:

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

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

比如例子中将C:UsersLiangAppDataLocalProgramsPythonPython38scripts添加到环境变量。

 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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/445440.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号