23 lines
506 B
Python
23 lines
506 B
Python
"""
|
|
PyInstaller 运行时 Hook
|
|
用于设置 Playwright 浏览器路径
|
|
"""
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def setup_playwright_path():
|
|
"""设置 Playwright 浏览器路径"""
|
|
if getattr(sys, 'frozen', False):
|
|
# 打包后运行
|
|
base_path = Path(sys._MEIPASS)
|
|
playwright_path = base_path / 'ms-playwright'
|
|
|
|
if playwright_path.exists():
|
|
os.environ['PLAYWRIGHT_BROWSERS_PATH'] = str(playwright_path)
|
|
|
|
|
|
# 执行设置
|
|
setup_playwright_path()
|