build: PyInstaller打包配置+启动器
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
"""
|
||||||
|
PyInstaller打包脚本
|
||||||
|
运行: python build_exe.py
|
||||||
|
输出: dist/cDNA_Analyzer.exe
|
||||||
|
"""
|
||||||
|
|
||||||
|
import PyInstaller.__main__
|
||||||
|
import os
|
||||||
|
|
||||||
|
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
PyInstaller.__main__.run([
|
||||||
|
'web/launcher.py',
|
||||||
|
'--name=cDNA_Analyzer',
|
||||||
|
'--onefile',
|
||||||
|
'--windowed',
|
||||||
|
'--add-data', f'web/templates;templates',
|
||||||
|
'--add-data', f'web/static;static',
|
||||||
|
'--hidden-import', 'skimage',
|
||||||
|
'--hidden-import', 'scipy.ndimage',
|
||||||
|
'--hidden-import', 'matplotlib.backends.backend_agg',
|
||||||
|
'--collect-all', 'skimage',
|
||||||
|
'--noconfirm',
|
||||||
|
'--clean',
|
||||||
|
])
|
||||||
|
print('\n完成!exe 在 dist/ 目录')
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# -*- mode: python ; coding: utf-8 -*-
|
||||||
|
from PyInstaller.utils.hooks import collect_all
|
||||||
|
|
||||||
|
datas = [('web/templates', 'templates'), ('web/static', 'static')]
|
||||||
|
binaries = []
|
||||||
|
hiddenimports = ['skimage', 'scipy.ndimage', 'matplotlib.backends.backend_agg']
|
||||||
|
tmp_ret = collect_all('skimage')
|
||||||
|
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(
|
||||||
|
['web\\launcher.py'],
|
||||||
|
pathex=[],
|
||||||
|
binaries=binaries,
|
||||||
|
datas=datas,
|
||||||
|
hiddenimports=hiddenimports,
|
||||||
|
hookspath=[],
|
||||||
|
hooksconfig={},
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
noarchive=False,
|
||||||
|
optimize=0,
|
||||||
|
)
|
||||||
|
pyz = PYZ(a.pure)
|
||||||
|
|
||||||
|
exe = EXE(
|
||||||
|
pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.datas,
|
||||||
|
[],
|
||||||
|
name='cDNA_Analyzer',
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
upx_exclude=[],
|
||||||
|
runtime_tmpdir=None,
|
||||||
|
console=False,
|
||||||
|
disable_windowed_traceback=False,
|
||||||
|
argv_emulation=False,
|
||||||
|
target_arch=None,
|
||||||
|
codesign_identity=None,
|
||||||
|
entitlements_file=None,
|
||||||
|
)
|
||||||
+11
-1
@@ -2,6 +2,7 @@
|
|||||||
cDNA微阵列图像处理 - Web UI (Flask)
|
cDNA微阵列图像处理 - Web UI (Flask)
|
||||||
=====================================
|
=====================================
|
||||||
启动:python web/app.py
|
启动:python web/app.py
|
||||||
|
打包:python build_exe.py
|
||||||
打开:http://localhost:5000
|
打开:http://localhost:5000
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -19,7 +20,16 @@ from scipy import ndimage
|
|||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
sys.path.insert(0, os.path.join(BASE_DIR, 'src'))
|
sys.path.insert(0, os.path.join(BASE_DIR, 'src'))
|
||||||
|
|
||||||
app = Flask(__name__)
|
# PyInstaller 打包后资源路径
|
||||||
|
if getattr(sys, 'frozen', False):
|
||||||
|
bundle_dir = sys._MEIPASS
|
||||||
|
template_dir = os.path.join(bundle_dir, 'templates')
|
||||||
|
static_dir = os.path.join(bundle_dir, 'static')
|
||||||
|
else:
|
||||||
|
template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
|
||||||
|
static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static')
|
||||||
|
|
||||||
|
app = Flask(__name__, template_folder=template_dir, static_folder=static_dir)
|
||||||
app.config['MAX_CONTENT_LENGTH'] = 50 * 1024 * 1024 # 50MB
|
app.config['MAX_CONTENT_LENGTH'] = 50 * 1024 * 1024 # 50MB
|
||||||
UPLOAD_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'uploads')
|
UPLOAD_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'uploads')
|
||||||
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"""cDNA Analyzer 启动器 — 供 PyInstaller 打包"""
|
||||||
|
import os, sys, threading
|
||||||
|
|
||||||
|
# PyInstaller 打包后资源路径
|
||||||
|
if getattr(sys, 'frozen', False):
|
||||||
|
base = sys._MEIPASS
|
||||||
|
else:
|
||||||
|
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
# 设置模板和静态文件目录
|
||||||
|
os.environ['TEMPLATE_DIR'] = os.path.join(base, 'templates')
|
||||||
|
os.environ['STATIC_DIR'] = os.path.join(base, 'static')
|
||||||
|
|
||||||
|
# 导入 Flask app
|
||||||
|
from app import app
|
||||||
|
|
||||||
|
def open_browser():
|
||||||
|
os.startfile('http://localhost:5000')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
threading.Timer(1.5, open_browser).start()
|
||||||
|
app.run(debug=False, port=5000)
|
||||||
Reference in New Issue
Block a user