build: PyInstaller打包配置+启动器
This commit is contained in:
+11
-1
@@ -2,6 +2,7 @@
|
||||
cDNA微阵列图像处理 - Web UI (Flask)
|
||||
=====================================
|
||||
启动:python web/app.py
|
||||
打包:python build_exe.py
|
||||
打开:http://localhost:5000
|
||||
"""
|
||||
|
||||
@@ -19,7 +20,16 @@ from scipy import ndimage
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
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
|
||||
UPLOAD_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'uploads')
|
||||
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