确保 playwright 已安装
()
| 125 | |
| 126 | |
| 127 | def _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 | |
| 157 | def _ensure_browser_installed() -> bool: |
no test coverage detected