fix(python): improve Python detection and pip command reliability

- Add shared python-utils.ts module for consistent Python detection
- Use `python -m pip` instead of direct pip command (fixes "pip not found")
- Support CCW_PYTHON env var for custom Python path
- Use Windows py launcher to find compatible versions (3.9-3.12)
- Warn users when Python version may not be compatible with onnxruntime

Fixes issues where users couldn't install ccw-litellm due to:
- pip not in PATH
- Only pip3 available (not pip)
- Python 3.13+ without onnxruntime support

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
catlog22
2025-12-30 15:23:44 +08:00
parent f6cc3736b2
commit 754cddd4ad
3 changed files with 133 additions and 22 deletions

View File

@@ -16,6 +16,7 @@ import { existsSync, mkdirSync } from 'fs';
import { join, dirname } from 'path';
import { homedir } from 'os';
import { fileURLToPath } from 'url';
import { getSystemPython } from '../utils/python-utils.js';
// Get directory of this module
const __filename = fileURLToPath(import.meta.url);
@@ -131,25 +132,7 @@ function clearVenvStatusCache(): void {
venvStatusCache = null;
}
/**
* Detect available Python 3 executable
* @returns Python executable command
*/
function getSystemPython(): string {
const commands = process.platform === 'win32' ? ['python', 'py', 'python3'] : ['python3', 'python'];
for (const cmd of commands) {
try {
const version = execSync(`${cmd} --version 2>&1`, { encoding: 'utf8' });
if (version.includes('Python 3')) {
return cmd;
}
} catch {
// Try next command
}
}
throw new Error('Python 3 not found. Please install Python 3 and ensure it is in PATH.');
}
// Python detection functions imported from ../utils/python-utils.js
/**
* Check if CodexLens venv exists and has required packages