Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
refactor(python): replace system pip installs with isolated per-user venv for Whisper dependencies
Gabriel Steinfbd7be6c10cb
diff --git a/LOCAL_WHISPER_SETUP.md b/LOCAL_WHISPER_SETUP.mdindex 86eccacaa..8945af088 100644--- a/LOCAL_WHISPER_SETUP.md+++ b/LOCAL_WHISPER_SETUP.md@@ -82,14 +82,17 @@ The following are now **bundled with the app** and require no user installation:- ✅ **Python Bridge Script**: Included in the app bundle- ✅ **App Integration**: Fully implemented-### 🔧 Optional Dependencies (For Local Whisper)+### 🔧 Isolated Python Environment (Default)-For **local Whisper processing**, users still need:+For **local Whisper processing**, OpenWhispr now:-- ✅ **Python 3**: Installed via Homebrew or system package manager-- ✅ **OpenAI Whisper**: Installed via `pip3 install openai-whisper`+- ✅ Creates a per-user virtual environment automatically+- ✅ Installs OpenAI Whisper inside that environment+- ✅ Avoids modifying system Python (no global `pip install`)-**Note**: FFmpeg is now bundled, so users no longer need to install it separately!+If you want to force a specific interpreter, set `OPENWHISPR_PYTHON` to a Python 3.x path before launching the app.++**Note**: FFmpeg is bundled, so users no longer need to install it separately.## 🧪 Testing Your Setup@@ -160,7 +163,13 @@ If you see this status:### Custom Python PathIf you need to force a specific interpreter, set the `OPENWHISPR_PYTHON` environment variable before launching the app (e.g. `setx OPENWHISPR_PYTHON "C:\\Python312\\python.exe"` on Windows or `export OPENWHISPR_PYTHON=/opt/homebrew/bin/python3.12` on macOS).-The new detector also scans the Windows `py` launcher plus the usual install folders, so manual code edits are no longer required.+When this is set, OpenWhispr will use that interpreter directly instead of its managed virtual environment, so ensure Whisper is installed in that environment.++### Managed Python Environment Location+The isolated environment lives under your app data directory:+- macOS: `~/Library/Application Support/OpenWhispr/python/venv`+- Windows: `%APPDATA%\\OpenWhispr\\python\\venv`+- Linux: `~/.config/OpenWhispr/python/venv`### Model Storage LocationModels are downloaded to `~/.cache/whisper/` by default.diff --git a/README.md b/README.mdindex f64f38e75..a14aa964a 100644--- a/README.md+++ b/README.md@@ -412,21 +412,23 @@ DEBUG=falseFor local processing, OpenWhispr offers automated setup:-1. **Automatic Python Installation** (if needed):- - The app will detect if Python is missing- - Offers to install Python 3.11 automatically- - macOS: Uses Homebrew if available, otherwise official installer- - Windows: Downloads and installs official Python- - Linux: Uses system package manager (apt, yum, or pacman)+1. **Isolated Python Environment** (default):+ - The app creates a per-user virtual environment under your app data folder+ - Uses a bundled Python runtime if present; otherwise uses system Python only to create the venv+ - No system-wide `pip install` is performed2. **Automatic Whisper Setup**:- - Installs OpenAI Whisper package via pip+ - Installs OpenAI Whisper inside the isolated environment- Downloads your chosen model on first use- Handles all transcription locally+Optional override: set `OPENWHISPR_PYTHON` to force a specific Python interpreter (advanced use).++Release packaging note: place a per-platform Python runtime under `resources/python` to bundle it with the app.+**Requirements**:- Sufficient disk space for models (39MB - 1.5GB depending on model)-- Admin/sudo access may be required for Python installation+- Admin/sudo access may be required only if you choose to install system Python### Customization@@ -477,8 +479,8 @@ OpenWhispr is designed with privacy and security in mind:- Set key through Control Panel or .env file- Check logs for "OpenAI API Key present: Yes/No"4. **Local Whisper installation**:- - Ensure Python 3.7+ is installed- - Use Control Panel to install Whisper automatically+ - OpenWhispr creates an isolated Python environment automatically+ - Use Control Panel to install Whisper into that environment- Check available disk space for models5. **Global hotkey conflicts**: Change the hotkey in the Control Panel - any key can be used6. **Text not pasting**: Check accessibility permissions and try manual paste with Cmd+V@@ -488,7 +490,7 @@ OpenWhispr is designed with privacy and security in mind:- Check the [Issues](https://github.com/your-repo/open-whispr/issues) page- Review the console logs for debugging information-- For local processing: Ensure Python and pip are working+- For local processing: Ensure the managed Python environment initializes successfully- For cloud processing: Verify your OpenAI API key and billing status- Check the Control Panel for system status and diagnosticsdiff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.mdindex e87d818ed..643e4ac1e 100644--- a/TROUBLESHOOTING.md+++ b/TROUBLESHOOTING.md@@ -55,10 +55,11 @@ If any of these look wrong (e.g., `x86_64` binaries on an Apple Silicon host), r**Resolution:**1. Verify you have a working Python 3: `python3 --version` and `which python3`. Apple Silicon should point to `/usr/bin/python3` or a Homebrew arm64 path.-2. Install Xcode Command Line Tools (`xcode-select --install`) so compilation helpers are available.-3. From the running app, open Settings → Whisper Models and click “Install Python” (uses the IPC bridge) or manually run the helper script `python3 setup.py` if supplied.-4. Delete `~/Library/Application Support/whisper` if partially downloaded models exist, then try again.-5. As a last resort, run `scripts/complete-uninstall.sh`, reboot, and rerun onboarding so the installer can download a clean toolchain.+2. OpenWhispr creates an isolated virtual environment under your user data directory. If it fails, delete the app’s `python/venv` folder and retry.+3. From the running app, open Settings → Whisper Models and click “Install Python” (uses the IPC bridge) or install Python manually from python.org.+4. If you see a “externally managed environment / PEP 668” error, you are trying to install into system Python. Use the app’s install button or unset `OPENWHISPR_PYTHON`.+5. Delete `~/Library/Application Support/whisper` if partially downloaded models exist, then try again.+6. As a last resort, run `scripts/complete-uninstall.sh`, reboot, and rerun onboarding so the installer can download a clean toolchain.### 5. Local Whisper can't find Python on Windows**Symptoms:** The toast shows `Whisper process error: spawn python ENOENT` as soon as transcription starts.diff --git a/WINDOWS_TROUBLESHOOTING.md b/WINDOWS_TROUBLESHOOTING.mdindex 3b3645901..62c8681d6 100644--- a/WINDOWS_TROUBLESHOOTING.md+++ b/WINDOWS_TROUBLESHOOTING.md@@ -47,21 +47,25 @@ This guide addresses common Windows-specific issues in OpenWhispr.- Wait for installation to complete- Restart OpenWhispr-2. **Manual Python Installation**+2. **Use the isolated environment (recommended)**+ - OpenWhispr installs Whisper into a per-user virtual environment automatically+ - If you set `OPENWHISPR_PYTHON`, unset it and restart so the app can manage its own environment++3. **Manual Python Installation**- Download Python 3.11+ from [python.org](https://www.python.org/downloads/)- **IMPORTANT**: Check "Add Python to PATH" during installation- Choose "Install for all users" if you have admin rights- After installation, restart your computer- Restart OpenWhispr-3. **Verify Python Installation**+4. **Verify Python Installation**- Open Command Prompt (Win + R, type `cmd`)- Type: `python --version`- Should show: `Python 3.x.x`- Type: `where python`- Should show path to python.exe-4. **Set Python Path Manually**+5. **Set Python Path Manually**- Find your Python installation (usually `C:\Users\YourName\AppData\Local\Programs\Python\Python311\python.exe`)- Create/edit `.env` file in OpenWhispr directory- Add: `OPENWHISPR_PYTHON=C:\Path\To\Your\python.exe`diff --git a/electron-builder.json b/electron-builder.jsonindex 94176828b..3840c8325 100644--- a/electron-builder.json+++ b/electron-builder.json@@ -31,7 +31,8 @@"extraResources": ["src/assets/**/*","resources/macos-globe-listener.swift",- "resources/bin/macos-globe-listener"+ "resources/bin/macos-globe-listener",+ "resources/python/**/*"],"mac": {"category": "public.app-category.productivity",diff --git a/resources/python/README.md b/resources/python/README.mdnew file mode 100644index 000000000..864961468--- /dev/null+++ b/resources/python/README.md@@ -0,0 +1,11 @@+Bundled Python runtime++Place per-platform Python runtimes in this folder during packaging.+OpenWhispr will prefer these binaries if present and create an isolated+virtual environment under the user's app data directory.++Expected layouts:+- Windows: resources/python/python.exe (python.org embeddable distribution)+- macOS/Linux: resources/python/bin/python3 (relocatable Python build)++This folder ships with the app via electron-builder extraResources.diff --git a/setup.js b/setup.jsindex e6dd225cc..76a0d8816 100644--- a/setup.js+++ b/setup.js@@ -44,7 +44,6 @@ Note: Make sure you have the necessary system permissions for:- Microphone access- Accessibility permissions (for text pasting)-For local Whisper processing, you'll also need:-- Python 3 (install via Homebrew: brew install python3)-- OpenAI Whisper (install via: pip3 install openai-whisper)+For local Whisper processing, OpenWhispr will create an isolated Python environment automatically.+If you want to use a custom interpreter, set OPENWHISPR_PYTHON to a valid Python 3.x path.`);diff --git a/src/helpers/pythonInstaller.js b/src/helpers/pythonInstaller.jsindex c449adc3a..9f0464f15 100644--- a/src/helpers/pythonInstaller.js+++ b/src/helpers/pythonInstaller.js@@ -205,8 +205,6 @@ class PythonInstaller {}async installPythonLinux(progressCallback = null) {- const platform = process.platform;-try {if (progressCallback) {progressCallback({ stage: "Detecting Linux distribution...", percentage: 10 });@@ -222,7 +220,25 @@ class PythonInstaller {}await runCommand("sudo", ["apt", "update"], { timeout: TIMEOUTS.PIP_UPGRADE });- await runCommand("sudo", ["apt", "install", "-y", "python3.11", "python3.11-pip", "python3.11-dev"], { timeout: TIMEOUTS.INSTALL });++ const preferredPackages = [+ "python3.11",+ "python3.11-pip",+ "python3.11-dev",+ "python3.11-venv"+ ];++ try {+ await runCommand("sudo", ["apt", "install", "-y", ...preferredPackages], { timeout: TIMEOUTS.INSTALL });+ } catch (installError) {+ const fallbackPackages = [+ "python3",+ "python3-pip",+ "python3-dev",+ "python3-venv"+ ];+ await runCommand("sudo", ["apt", "install", "-y", ...fallbackPackages], { timeout: TIMEOUTS.INSTALL });+ }if (progressCallback) {progressCallback({ stage: "Python installation complete!", percentage: 100 });@@ -299,59 +315,6 @@ class PythonInstaller {}}- async isPythonInstalled() {- const possibleCommands = ['python3.11', 'python3', 'python'];-- // On macOS, also check common Python installation paths- const additionalPaths = process.platform === 'darwin' ? [- '/usr/local/bin/python3',- '/usr/local/bin/python3.11',- '/opt/homebrew/bin/python3',- '/opt/homebrew/bin/python3.11',- '/usr/bin/python3',- '/Library/Frameworks/Python.framework/Versions/3.11/bin/python3',- '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3',- '/Library/Frameworks/Python.framework/Versions/3.9/bin/python3',- ] : [];-- // First check commands in PATH- for (const cmd of possibleCommands) {- try {- const result = await runCommand(cmd, ['--version'], { timeout: TIMEOUTS.QUICK_CHECK });- const versionMatch = result.output.match(/Python (\d+\.\d+)/);- if (versionMatch) {- const version = parseFloat(versionMatch[1]);- // Accept any Python 3.x version- if (version >= 3.0) {- return { installed: true, command: cmd, version: version };- }- }- } catch (error) {- continue;- }- }-- // Then check absolute paths on macOS- for (const fullPath of additionalPaths) {- try {- const fs = require('fs');- if (fs.existsSync(fullPath)) {- const result = await runCommand(fullPath, ['--version'], { timeout: TIMEOUTS.QUICK_CHECK });- const versionMatch = result.output.match(/Python (\d+\.\d+)/);- if (versionMatch) {- const version = parseFloat(versionMatch[1]);- if (version >= 3.0) {- return { installed: true, command: fullPath, version: version };- }- }- }- } catch (error) {- continue;- }- }-- return { installed: false };- }}-module.exports = PythonInstaller;\ No newline at end of file+module.exports = PythonInstaller;diff --git a/src/helpers/whisper.js b/src/helpers/whisper.jsindex 4da42fcca..ab205bfc2 100644--- a/src/helpers/whisper.js+++ b/src/helpers/whisper.js@@ -1,4 +1,5 @@const { spawn } = require("child_process");+const { app } = require("electron");const fs = require("fs");const fsPromises = require("fs").promises;const os = require("os");@@ -16,6 +17,9 @@ class WhisperManager {this.currentDownloadProcess = null;this.pythonInstaller = new PythonInstaller();this.cachedFFmpegPath = null;+ this.bundledPythonPath = null;+ this.bundledPythonChecked = false;+ this.venvReadyPromise = null;}sanitizeErrorMessage(message = "") {@@ -25,19 +29,6 @@ class WhisperManager {return message.replace(/\x1B\[[0-9;]*m/g, "");}- shouldRetryWithUserInstall(message = "") {- const normalized = this.sanitizeErrorMessage(message).toLowerCase();- const shouldUseUser = (- normalized.includes("permission denied") ||- normalized.includes("access is denied") ||- normalized.includes("externally-managed-environment") ||- normalized.includes("externally managed environment") ||- normalized.includes("pep 668") ||- normalized.includes("--break-system-packages")- );- return shouldUseUser;- }-isTomlResolverError(message = "") {const normalized = this.sanitizeErrorMessage(message).toLowerCase();return (@@ -53,13 +44,187 @@ class WhisperManager {return "Microsoft Visual C++ build tools required. Install Visual Studio Build Tools.";}+ if (+ lower.includes("externally-managed-environment") ||+ lower.includes("externally managed environment") ||+ lower.includes("pep 668") ||+ lower.includes("--break-system-packages")+ ) {+ return "System Python is externally managed (PEP 668). OpenWhispr installs Whisper into an isolated environment by default. If you set OPENWHISPR_PYTHON, unset it or point it to a virtual environment, then try again.";+ }+if (lower.includes("no matching distribution")) {- return "Python version incompatible. OpenAI Whisper requires Python 3.8-3.11.";+ return "Python version incompatible. Whisper requires a supported Python 3.x runtime.";}return formatted;}+ getUserDataDir() {+ try {+ if (app && app.getPath) {+ return app.getPath("userData");+ }+ } catch (error) {+ // Fall back to home directory+ }+ return path.join(os.homedir(), ".openwhispr");+ }++ getManagedPythonRoot() {+ return path.join(this.getUserDataDir(), "python");+ }++ getVenvPath() {+ return path.join(this.getManagedPythonRoot(), "venv");+ }++ getVenvPythonPath() {+ const venvPath = this.getVenvPath();+ if (process.platform === "win32") {+ return path.join(venvPath, "Scripts", "python.exe");+ }+ const python3Path = path.join(venvPath, "bin", "python3");+ if (fs.existsSync(python3Path)) {+ return python3Path;+ }+ return path.join(venvPath, "bin", "python");+ }++ getBundledPythonCandidates() {+ const baseDirs = [];+ if (process.resourcesPath) {+ baseDirs.push(path.join(process.resourcesPath, "python"));+ }+ baseDirs.push(path.join(__dirname, "..", "..", "resources", "python"));++ const candidates = [];+ const uniqueBaseDirs = Array.from(new Set(baseDirs));++ for (const baseDir of uniqueBaseDirs) {+ if (!baseDir) {+ continue;+ }+ if (process.platform === "win32") {+ candidates.push(+ path.join(baseDir, "python.exe"),+ path.join(baseDir, "python", "python.exe")+ );+ } else {+ candidates.push(+ path.join(baseDir, "bin", "python3"),+ path.join(baseDir, "bin", "python"),+ path.join(baseDir, "python3")+ );+ }+ }++ return candidates;+ }++ resolveBundledPython() {+ if (this.bundledPythonChecked) {+ return this.bundledPythonPath;+ }++ this.bundledPythonChecked = true;+ for (const candidate of this.getBundledPythonCandidates()) {+ if (candidate && fs.existsSync(candidate)) {+ this.bundledPythonPath = candidate;+ return candidate;+ }+ }++ this.bundledPythonPath = null;+ return null;+ }++ normalizePathForCompare(candidate) {+ if (!candidate) {+ return "";+ }+ const normalized = path.normalize(candidate);+ return process.platform === "win32" ? normalized.toLowerCase() : normalized;+ }++ getPythonSource(pythonPath) {+ const normalizedPath = this.normalizePathForCompare(pythonPath);+ const normalizedVenv = this.normalizePathForCompare(this.getVenvPath());+ const bundled = this.resolveBundledPython();+ const normalizedBundled = this.normalizePathForCompare(bundled);+ const normalizedOverride = this.normalizePathForCompare(process.env.OPENWHISPR_PYTHON);++ if (normalizedVenv && normalizedPath.startsWith(normalizedVenv)) {+ return "venv";+ }+ if (normalizedBundled && normalizedPath === normalizedBundled) {+ return "bundled";+ }+ if (normalizedOverride && normalizedPath === normalizedOverride) {+ return "override";+ }+ return "system";+ }++ async ensureManagedVenv() {+ if (process.env.OPENWHISPR_PYTHON) {+ return process.env.OPENWHISPR_PYTHON;+ }++ if (this.venvReadyPromise) {+ return this.venvReadyPromise;+ }++ this.venvReadyPromise = (async () => {+ const venvPath = this.getVenvPath();+ const venvPython = this.getVenvPythonPath();++ if (fs.existsSync(venvPython)) {+ const version = await this.getPythonVersion(venvPython);+ if (this.isPythonVersionSupported(version)) {+ this.pythonCmd = venvPython;+ return venvPython;+ }++ try {+ fs.rmSync(venvPath, { recursive: true, force: true });+ } catch (error) {+ // Continue and attempt to recreate+ }+ }++ let basePython;+ try {+ basePython = await this.findPythonExecutable({ allowVenv: false });+ } catch (error) {+ throw new Error(+ "Python 3.x not found. Install Python from Settings or set OPENWHISPR_PYTHON to a valid interpreter."+ );+ }++ fs.mkdirSync(this.getManagedPythonRoot(), { recursive: true });+ try {+ await runCommand(basePython, ["-m", "venv", venvPath], { timeout: TIMEOUTS.INSTALL });+ } catch (error) {+ const cleanMessage = this.sanitizeErrorMessage(error.message).toLowerCase();+ if (cleanMessage.includes("no module named venv")) {+ throw new Error(+ "Python venv module missing. Install the venv package for your Python distribution and try again."+ );+ }+ throw error;+ }++ this.pythonCmd = venvPython;+ return venvPython;+ })().catch((error) => {+ this.venvReadyPromise = null;+ throw error;+ });++ return this.venvReadyPromise;+ }+getWhisperScriptPath() {// In production, the file is unpacked from ASARif (process.env.NODE_ENV === "development") {@@ -565,9 +730,25 @@ class WhisperManager {}}- async findPythonExecutable() {+ async findPythonExecutable(options = {}) {+ const {+ allowVenv = true,+ allowBundled = true,+ allowOverride = true,+ } = options;+if (this.pythonCmd) {- return this.pythonCmd;+ const cachedSource = this.getPythonSource(this.pythonCmd);+ const cachedExists = !path.isAbsolute(this.pythonCmd) || fs.existsSync(this.pythonCmd);+ if (+ cachedExists &&+ (cachedSource !== "venv" || allowVenv) &&+ (cachedSource !== "bundled" || allowBundled) &&+ (cachedSource !== "override" || allowOverride)+ ) {+ return this.pythonCmd;+ }+ this.pythonCmd = null;}const candidateSet = new Set();@@ -582,10 +763,21 @@ class WhisperManager {candidateSet.add(sanitized);};- if (process.env.OPENWHISPR_PYTHON) {+ if (allowOverride && process.env.OPENWHISPR_PYTHON) {addCandidate(process.env.OPENWHISPR_PYTHON);}+ if (allowVenv) {+ addCandidate(this.getVenvPythonPath());+ }++ if (allowBundled) {+ const bundledPython = this.resolveBundledPython();+ if (bundledPython) {+ addCandidate(bundledPython);+ }+ }+if (process.platform === "win32") {// Windows: Get registry-based candidates first (most reliable)const registryCandidates = await this.getWindowsRegistryPython();@@ -809,17 +1001,28 @@ class WhisperManager {try {// Clear cached Python command since we're installing new onethis.pythonCmd = null;-- const result = await this.pythonInstaller.installPython(progressCallback);-- // After installation, try to find Python again- try {- await this.findPythonExecutable();- return result;- } catch (findError) {- throw new Error("Python installed but not found in PATH. Please restart the application.");++ const bundledPython = this.resolveBundledPython();+ if (bundledPython) {+ if (progressCallback) {+ progressCallback({ stage: "Using bundled Python runtime...", percentage: 40 });+ }++ await this.ensureManagedVenv();++ if (progressCallback) {+ progressCallback({ stage: "Python ready", percentage: 100 });+ }++ return { success: true, method: "bundled" };}-++ const result = await this.pythonInstaller.installPython(progressCallback);++ // After installation, prepare isolated environment+ await this.ensureManagedVenv();++ return result;} catch (error) {console.error("Python installation failed:", error);throw error;@@ -827,7 +1030,20 @@ class WhisperManager {}async checkPythonInstallation() {- return await this.pythonInstaller.isPythonInstalled();+ try {+ const pythonPath = await this.findPythonExecutable();+ const version = await this.getPythonVersion(pythonPath);+ const normalizedVersion = version ? parseFloat(`${version.major}.${version.minor}`) : undefined;++ return {+ installed: !!version,+ command: pythonPath,+ version: normalizedVersion,+ source: this.getPythonSource(pythonPath),+ };+ } catch (error) {+ return { installed: false };+ }}async getPythonVersion(pythonPath) {@@ -994,81 +1210,59 @@ class WhisperManager {}upgradePip(pythonCmd) {- return runCommand(pythonCmd, ["-m", "pip", "install", "--upgrade", "pip"], { timeout: TIMEOUTS.PIP_UPGRADE });+ return runCommand(+ pythonCmd,+ ["-m", "pip", "install", "--upgrade", "pip"],+ { timeout: TIMEOUTS.PIP_UPGRADE }+ );}// Removed - now using shared runCommand from utils/process.jsasync installWhisper() {- const pythonCmd = await this.findPythonExecutable();-- // Upgrade pip first to avoid version issues+ if (!process.env.OPENWHISPR_PYTHON) {+ console.log("Preparing isolated Python environment...");+ }++ const pythonCmd = process.env.OPENWHISPR_PYTHON+ ? process.env.OPENWHISPR_PYTHON+ : await this.ensureManagedVenv();++ // Upgrade pip inside the isolated environment to avoid resolver issuestry {await this.upgradePip(pythonCmd);} catch (error) {const cleanUpgradeError = this.sanitizeErrorMessage(error.message);- debugLogger.log("First pip upgrade attempt failed:", cleanUpgradeError);-- // Try user install for pip upgrade- try {- await runCommand(pythonCmd, ["-m", "pip", "install", "--user", "--upgrade", "pip"], { timeout: TIMEOUTS.PIP_UPGRADE });- } catch (userError) {- const cleanUserError = this.sanitizeErrorMessage(userError.message);- // If pip upgrade fails completely, try to detect if it's the TOML error- if (this.isTomlResolverError(cleanUpgradeError) || this.isTomlResolverError(cleanUserError)) {- // Try installing with legacy resolver as a workaround- try {- await runCommand(pythonCmd, ["-m", "pip", "install", "--use-deprecated=legacy-resolver", "--upgrade", "pip"], { timeout: TIMEOUTS.PIP_UPGRADE });- } catch (legacyError) {- throw new Error("Failed to upgrade pip. Please manually run: python -m pip install --upgrade pip");- }- } else {- debugLogger.log("Pip upgrade failed completely, attempting to continue");- }- }+ debugLogger.log("Pip upgrade failed in managed environment:", cleanUpgradeError);}-- const buildInstallArgs = ({ user = false, legacy = false } = {}) => {++ const buildInstallArgs = ({ legacy = false } = {}) => {const args = ["-m", "pip", "install"];if (legacy) {args.push("--use-deprecated=legacy-resolver");}- if (user) {- args.push("--user");- }args.push("-U", "openai-whisper");return args;};-+try {- return await runCommand(pythonCmd, buildInstallArgs(), { timeout: TIMEOUTS.DOWNLOAD });+ const result = await runCommand(pythonCmd, buildInstallArgs(), { timeout: TIMEOUTS.DOWNLOAD });+ this.whisperInstalled = null;+ return result;} catch (error) {const cleanMessage = this.sanitizeErrorMessage(error.message);-- if (this.shouldRetryWithUserInstall(cleanMessage)) {- try {- return await runCommand(pythonCmd, buildInstallArgs({ user: true }), { timeout: TIMEOUTS.DOWNLOAD });- } catch (userError) {- const userMessage = this.sanitizeErrorMessage(userError.message);- if (this.isTomlResolverError(userMessage)) {- return await runCommand(pythonCmd, buildInstallArgs({ user: true, legacy: true }), { timeout: TIMEOUTS.DOWNLOAD });- }- throw new Error(this.formatWhisperInstallError(userMessage));- }- }-+if (this.isTomlResolverError(cleanMessage)) {try {- return await runCommand(pythonCmd, buildInstallArgs({ legacy: true }), { timeout: TIMEOUTS.DOWNLOAD });+ const result = await runCommand(pythonCmd, buildInstallArgs({ legacy: true }), { timeout: TIMEOUTS.DOWNLOAD });+ this.whisperInstalled = null;+ return result;} catch (legacyError) {const legacyMessage = this.sanitizeErrorMessage(legacyError.message);- if (this.shouldRetryWithUserInstall(legacyMessage)) {- return await runCommand(pythonCmd, buildInstallArgs({ user: true, legacy: true }), { timeout: TIMEOUTS.DOWNLOAD });- }throw new Error(this.formatWhisperInstallError(legacyMessage));}}-+throw new Error(this.formatWhisperInstallError(cleanMessage));}}diff --git a/src/types/electron.ts b/src/types/electron.tsindex 058462734..04bc03e9e 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -90,6 +90,7 @@ export interface PythonInstallation {installed: boolean;command?: string;version?: number;+ source?: string;}export interface PythonInstallResult {