iT邦幫忙

2021 iThome 鐵人賽

DAY 11
1
AI & Data

機器學習與前端網頁系列 第 11

Day 11 打包 python 程式-3

接續上一篇

我們再把 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


上一篇
Day 10 打包 python 程式-2
下一篇
Day 12 跑 Tensorflow Serving Docker 範例
系列文
機器學習與前端網頁30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言