pyinstaller 打包应用问题集合
一、安装pyinstaller
直接使用 pip install pyinstaller ,如果直接 install 的不行可以去下载源码编译下
pyinstaller 源码地址:GitHub - pyinstaller/pyinstaller: Freeze (package) Python programs into stand-alone executables
下载源码后在源码目录执行如下指令
cd bootloader
python ./waf allpython setup.py install
二、打包命令
执行 pyinstaller -F -w MainTool.py 将代码打包成 exe 文件。
执行pyinstaller -F 可能会报如下错误
15522 INFO: Bootloader D:\Python2017\lib\site-packages\pyinstaller-5.0.dev0-py3.6.egg\PyInstaller\bootloader\Windows-64bit\runw.exe
15522 INFO: checking EXEFatal error: PyInstaller doesnotinclude a pre-compiled bootloaderforyour platform
这是PyInstaller\bootloader\Windows-64bit\ 下没有找到 run.exe ,需要查看下文件是否存在。我遇到文件不存在的原因是:电脑本地 **杀毒软件给我把这个 run.exe 给我杀掉删除了 QAQ,后面给它路径加了白名单才好。
-F, –onefile | 打包成单个文件 |
-D, –onedir | 打包多个文件,在dist中生成多个依赖文件,易于维护 |
-a, –ascii | 不包含编码.在支持Unicode的python版本上默认包含所有的编码 |
-d, –debug | 产生debug版本的可执行文件 |
-w, –windowed,–noconsole | 使用Windows子系统执行.当程序启动的时候不会打开命令行 |
-c,–nowindowed,–console | 使用控制台子系统执行(默认模式) |
-s,–strip | 可执行文件和共享库将run through strip |
-X, –upx | 如果有UPX安装(执行Configure.py时检测),会压缩执行文件(Windows系统中的DLL也会) |
-o DIR, –out=DIR | 指定spec文件的生成目录 |
-p DIR, –path=DIR | 设置依赖目录,多个目录使用封号 ; (windows环境) 或者冒号 : (Linux环境)连接 |
-i FILE.ICO, –icon=<FILE.ICO> | 设置程序 icon |
-v FILE, –version=FILE | 指定程序的版本文件 |
-n NAME, –name=NAME | 程序名称,默认与被打包py文件同名 |
三、通过 spec 文件打包
通过指令方式打包,在文件和依赖库比较多的时候,命令行会很长,很不方便,也容易写错。这个时候通过 spec 进行打包即可。
3.1、spec 文件生成
首先执行如下指令
pyinstaller -F test.py
然后根目录下就生成一个 test.spec 文件,内容大致如下:
# -*- mode: python -*-
block_cipher = None
py_files = [ # 项目需要的所有python脚本
'bin\\setup.py',
'conf\\settings.py',
'core\\main.py',
'core\\pipe.py',
]add_files = [ # 项目需要的所有资源文件
('fonts\\font.ttf', 'fonts'),
('images\\test.ico', 'images'),
('audios\\*.wav', 'audios'),
]a = Analysis(['test.py'],
pathex=['E:\\pythonDemo\\Test',], # 项目依赖库的绝对路径,有多个路径使用 , 隔开
binaries=None,
datas=None,
hiddenimports=["getPublicKey","imp"], # 填写项目依赖的非根目录下的库
hookspath=None,
runtime_hooks=None,
excludes=None,
win_no_prefer_redirects=None,
win_private_assemblies=None,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='test', # 填写程序名称
debug=False,
strip=None,
upx=True,
console=True # console=True表示,打包后的可执行文件双击运行时屏幕会出现一个cmd窗口
icon='E:\\pythonDemo\\Test\\test.ico') # 填写程序图标绝对路径
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=None,
upx=True,
name='test')
通过修改 spec 中相关设置项,再执行 pyinstaller -F test.spec 即可。
pyinstaller 打包应用问题集合相关推荐
- Python使用pyinstaller打包几个小技巧
1.进入命令提示符环境cmd,执行命令pip install pyinstaller安装扩展库pyinstaller. 2.编写Python程序,以<Python可以这样学>书中的电子时钟 ...
- Pyinstaller 打包 torch 后执行失败 OSError: could not get source code
1. 问题现象 系统环境 Python 3.6.9 torch 1.2.0 torchvision 0.4.0 Pyinstaller 4.5.1 Pyinstaller 打包 torch 后执行失败 ...
- pyinstaller打包生成的exe文件(并设置运行时静默)
pyinstaller打包生成的exe文件(并设置运行时静默) 目录 pyinstaller打包生成的exe文件(并设置运行时静默)
- pyinstaller打包生成的exe文件并使用python终止后台的exe程序运行
pyinstaller打包生成的exe文件并使用python终止后台的exe程序运行 目录 pyinstaller打包生成的exe文件并使用python终止后台的exe程序运行 #pyinstalle ...
- Python执行pyinstaller打包生成的exe文件实战
Python执行pyinstaller打包生成的exe文件实战 目录 Python执行pyinstaller打包生成的exe文件实战 #pyinstaller打包生成的exe文件
- pyinstaller打包之后运行出现:Could not find the matplotlib data files
pyinstaller 打包之后Could not find the matplotlib data files 目录 pyinstaller 打包之后Could not find the matpl ...
- pyinstaller打包任何py文件TypeError: an integer is required (got type bytes)
pyinstaller打包任何py文件TypeError: an integer is required (got type bytes) 目录 pyinstaller打包任何py文件TypeErro ...
- pyinstaller打包venv(虚拟环境),.pyd文件,非.py文件打包
pyinstaller打包venv(虚拟环境),.pyd文件,非.py文件打包 1 首先pyinstaller不会使用venv中的包,请先进入虚拟环境,然后再使用 pyinstaller xxx.py ...
- pyinstaller打包教程及错误RuntimeError: Unable to open ./shape_predictor_68_face_landmarks.dat
pyinstaller打包教程及错误RuntimeError: Unable to open ./shape_predictor_68_face_landmarks.dat pyinstaller基本 ...
最新文章
- ajax状态码--转他人的
- 怎么将织梦图集模型编辑器改为文章编辑器?
- Linux程序包管理(yum)
- 读取模式错误,计算引擎操作复杂……面对Hadoop这些问题该如何应对?
- 敏捷需求分析及深度提升(广州 2014.1.11)
- Deep Learning的基本思想以及训练过程
- 中兴ZTE ZXR10系列交换机2818S固件以及更新方法
- Julia:关于split的用法
- android 存储盘 dcim,Android上的DCIM目录路径 – 返回值
- Markdown编辑器如何配置图片大小
- zbbix服务器搭建_Linux系统搭建Zabbix监控服务器
- 华为nova手机打开开发者模式
- 做人做事箴言录(4)
- vue 多种方法实现名字拼接
- java基于springboot足球联赛管理系统
- 中国重大铁路事故一览,90年代以前基本都是爆炸事故,90年代以后基本都是追尾事故
- unity3d插入android有米广告
- 怎样找到ant压缩这个软件_千辛万苦才找到这个强大的剪辑软件(pr),看看安装会不会很顺利...
- 利用魔法数实现快速开平方
- Vertica数据查询优化