MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / _ensure_playwright_installed

Function _ensure_playwright_installed

src/services/browser_captcha.py:127–154  ·  view source on GitHub ↗

确保 playwright 已安装

()

Source from the content-addressed store, hash-verified

125
126
127def _ensure_playwright_installed() -> bool:
128 """确保 playwright 已安装"""
129 try:
130 import playwright
131 debug_logger.log_info("[BrowserCaptcha] playwright 已安装")
132 return True
133 except ImportError:
134 pass
135
136 debug_logger.log_info("[BrowserCaptcha] playwright 未安装,开始自动安装...")
137 progress_runtime_prepare("browser", "[BrowserCaptcha] playwright 未安装,开始自动安装...")
138 print("[BrowserCaptcha] playwright 未安装,开始自动安装...")
139
140 # 先尝试官方源
141 if _run_pip_install('playwright', use_mirror=False):
142 return True
143
144 # 官方源失败,尝试国内镜像
145 debug_logger.log_info("[BrowserCaptcha] 官方源安装失败,尝试国内镜像...")
146 progress_runtime_prepare("browser", "[BrowserCaptcha] 官方源安装失败,尝试国内镜像...")
147 print("[BrowserCaptcha] 官方源安装失败,尝试国内镜像...")
148 if _run_pip_install('playwright', use_mirror=True):
149 return True
150
151 debug_logger.log_error("[BrowserCaptcha] ❌ playwright 自动安装失败,请手动安装: pip install playwright")
152 fail_runtime_prepare("browser", "[BrowserCaptcha] ❌ playwright 自动安装失败,请手动安装: pip install playwright")
153 print("[BrowserCaptcha] ❌ playwright 自动安装失败,请手动安装: pip install playwright")
154 return False
155
156
157def _ensure_browser_installed() -> bool:

Callers 1

browser_captcha.pyFile · 0.85

Calls 5

progress_runtime_prepareFunction · 0.85
fail_runtime_prepareFunction · 0.85
log_infoMethod · 0.80
log_errorMethod · 0.80
_run_pip_installFunction · 0.70

Tested by

no test coverage detected