import PyInsatller.building.templates as pyi_spec_templatesfrom PyInstaller.__main__ import run as pyi_build
# copy from PyInsatller.building.templates.py# add datas and binaries filter after Analysisonefiletmplate = """# -*- mode: python ; coding: utf-8 -*-%(preamble)s
a = Analysis( %(scripts)s, pathex=%(pathex)s, binaries=%(binaries)s, datas=%(datas)s, hiddenimports=%(hiddenimports)s, hookspath=%(hookspath)r, hooksconfig={}, runtime_hooks=%(runtime_hooks)r, excludes=%(excludes)s, noarchive=%(noarchive)s, optimize=%(optimize)r,)
# begin filter any datas you wantdatas = []for dest_name, src_name, res_type in a.datas: # 在这里添加过滤逻辑 datas.append((dest_name, src_name, res_type))a.datas = datas# end filter datas
# begin filter any binaries you wantbinaries = []for dest_name, src_name, res_type in a.binaries: # 在这里添加过滤逻辑 binaries.append((dest_name, src_name, res_type))a.binaries = binaries# end filter datas
pyz = PYZ(a.pure)%(splash_init)sexe = EXE( pyz, a.scripts, a.binaries, a.datas,%(splash_target)s%(splash_binaries)s %(options)s, name='%(name)s', debug=%(debug_bootloader)s, bootloader_ignore_signals=%(bootloader_ignore_signals)s, strip=%(strip)s, upx=%(upx)s, upx_exclude=%(upx_exclude)s, runtime_tmpdir=%(runtime_tmpdir)r, console=%(console)s, disable_windowed_traceback=%(disable_windowed_traceback)s, argv_emulation=%(argv_emulation)r, target_arch=%(target_arch)r, codesign_identity=%(codesign_identity)r, entitlements_file=%(entitlements_file)r,%(exe_options)s)"""
pyi_spec_templates.onefiletmplt = onefiletmplate # ==> patch the template string here
# build exepyi_build(['main.py', '--onefile', ...])
评论