接續上一篇
我們再把 keras.engine.base_layer_v1 加入到 hiddenimports 中。
# a00_flask_server.spec
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
from PyInstaller import log as logging
from PyInstaller import compat
from os import listdir
binaries = []
mkldir = compat.base_prefix + "\\Library\\bin"
binaries.extend([(mkldir + "\\" + mkl, '.') for mkl in listdir(mkldir) if mkl.startswith('mkl_')])
binaries.append((compat.base_prefix +
"\\Lib\site-packages\\tensorflow\\lite\\experimental\\microfrontend\\python\\ops",
"tensorflow\\lite\\experimental\\microfrontend\\python\\ops"))
a = Analysis(['a01_flask_server.py'],
pathex=['D:\\vscode\\ithelp'],
binaries=binaries,
datas=[("mnist", "mnist")],
hiddenimports=["keras.api", "keras.api._v2", "keras.engine.base_layer_v1"],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='a01_flask_server',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='a01_flask_server')
然後再跑一次...雖然出現各種 warning,但至少跑起來了。
最後連看看。
index.html 沒包進去。
讓pyinstaller 包裝時自動包進去
# a01_flask_server.spec
datas=[("mnist", "mnist"), ("templates", "templates")],
flask 這邊,設定 template_folder 位置。
# a01_flask_server.py
app = Flask("mnist", template_folder= os.path.dirname(__file__) + '\\templates')
這算是成功了吧...
總大小 接近2G