()
| 30 | |
| 31 | const tmpFile = path.resolve(getAppTmpDir(), "tmp.py"); |
| 32 | export async function verifyIsTorchInstalled(): Promise<boolean> { |
| 33 | const { PIP_PATH, PYTHON_PATH } = conda.getCondaPaths(); |
| 34 | try { |
| 35 | await writeTmpPythonFile(pythonCode); |
| 36 | // 使用 execa 执行 conda run 命令,切换到指定的 Conda 环境并运行 Python 代码 |
| 37 | const { stdout } = await runCommand(`${PYTHON_PATH} ${tmpFile}`); |
| 38 | |
| 39 | // 检查执行结果是否符合预期 |
| 40 | if (stdout.trim() === expectedOutput) { |
| 41 | logger.info('Torch installation verification successful.'); |
| 42 | return true; |
| 43 | } else { |
| 44 | console.error('Torch installation verification failed. Unexpected output.'); |
| 45 | return false; |
| 46 | } |
| 47 | } catch (error) { |
| 48 | console.error('Torch installation verification failed. Error:', error); |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | export async function writeTmpPythonFile(code: string) { |
| 54 | await fsExtra.writeFile(tmpFile, code, 'utf8'); |
no test coverage detected