700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python打包为exe文件_Pyinstaller(python打包为exe文件)

python打包为exe文件_Pyinstaller(python打包为exe文件)

时间:2022-04-01 17:08:48

相关推荐

python打包为exe文件_Pyinstaller(python打包为exe文件)

需求分析:

python脚本如果在没有安装python的机器上不能运行,所以将脚本打包成exe文件,降低脚本对环境的依赖性,同时运行更加迅速。

当然打包的脚本似乎不是在所有的win平台下都能使用,win7有一部分不能使用,我在win10能够很好的运行。

准备:

pyinstaller(/) 首先还是去官网看支持的python版本,不然会很尴尬的

#安装方法1:

#安装pyinstaller和pywin32

#使用一下命令将自动安装两个包,在cmd用pip命令

#pip install -i /simple/ pyinstaller(豆瓣源)

安装方法二:

pip install pyinstaller (会自动下载future,pywin32,pyinstaller)

如何使用Pyinstaller

方法一:

1.cmd到/python/scripts 找到pyinstaller.exe

2.输入命令

1

pyinstaller.exe -F path:demo.py

方法二:

1.进入pyinstaller的解压包,输入命令

2."python pyinstaller.py -F path:demo.py"

从cmd最后一行输出可查找到生成的文件

12468 INFO: Appending archive to EXE D:\Documents\Downloads\PyInstaller-3.2\down

load\dist\download.exe

后记:

1.程序设置自定义图标:pyinstaller -F -i ico_path py_path

首先需要下载一张正常的ico,不能用直接修改后缀的。

下载图片:

图片改为ico:http://www.ico.la/

输入命令 pyinstaller -F -i "demo.ico" "main.py"

2.报错提示:

pyinstaller -F -i "demo.ico" "main.py" 命令格式一定是先图标路径,再程序路径。

路径最好为英文,没有中文字符;脚本名称里没有特殊字符如 .

使用utf8编码

图标文件必须是正常格式,不能直接更改后缀。

tuble index out of range ---》pyinstaller版本尚未支持python的版本

3.窗口程序

使用 pyinstaller -F -w -i ico_path py_path ,这样脚本不会弹出命令窗,前提是用了GUI库.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。