运行 pip install 命令
(package: str, use_mirror: bool = False)
| 71 | |
| 72 | # ==================== playwright 自动安装 ==================== |
| 73 | def _run_pip_install(package: str, use_mirror: bool = False) -> bool: |
| 74 | """运行 pip install 命令""" |
| 75 | cmd = [sys.executable, '-m', 'pip', 'install', package] |
| 76 | if use_mirror: |
| 77 | cmd.extend(['-i', 'https://pypi.tuna.tsinghua.edu.cn/simple']) |
| 78 | |
| 79 | try: |
| 80 | debug_logger.log_info(f"[BrowserCaptcha] 正在安装 {package}...") |
| 81 | progress_runtime_prepare("browser", f"[BrowserCaptcha] 正在安装 {package}...") |
| 82 | print(f"[BrowserCaptcha] 正在安装 {package}...") |
| 83 | result = subprocess.run(cmd, capture_output=True, text=True, timeout=300) |
| 84 | if result.returncode == 0: |
| 85 | debug_logger.log_info(f"[BrowserCaptcha] ✅ {package} 安装成功") |
| 86 | print(f"[BrowserCaptcha] ✅ {package} 安装成功") |
| 87 | return True |
| 88 | else: |
| 89 | debug_logger.log_warning(f"[BrowserCaptcha] {package} 安装失败: {result.stderr[:200]}") |
| 90 | fail_runtime_prepare("browser", f"{package} 安装失败,请检查网络或 Python 环境。") |
| 91 | return False |
| 92 | except Exception as e: |
| 93 | debug_logger.log_warning(f"[BrowserCaptcha] {package} 安装异常: {e}") |
| 94 | fail_runtime_prepare("browser", f"{package} 安装异常: {e}") |
| 95 | return False |
| 96 | |
| 97 | |
| 98 | def _run_playwright_install(use_mirror: bool = False) -> bool: |
no test coverage detected