Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(python): validate OPENWHISPR_PYTHON override, add venv packages for yum/pacman, update bundled Python docs to require full distribution

Gabriel Stein6a379439b5af
diff --git a/resources/python/README.md b/resources/python/README.md
index 864961468..531a9c111 100644
--- a/resources/python/README.md
+++ b/resources/python/README.md
@@ -4,8 +4,17 @@ 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.
+IMPORTANT: The bundled Python MUST include venv and ensurepip modules.
+The Windows embeddable distribution does NOT include these - use the full
+installer or a relocatable build instead.
+
Expected layouts:
-- Windows: resources/python/python.exe (python.org embeddable distribution)
+- Windows: resources/python/python.exe (full installer, NOT embeddable)
- macOS/Linux: resources/python/bin/python3 (relocatable Python build)
+Requirements for bundled Python:
+- Python 3.8+ (3.11 recommended)
+- venv module (python -m venv must work)
+- ensurepip module (for pip bootstrapping)
+
This folder ships with the app via electron-builder extraResources.
diff --git a/src/helpers/pythonInstaller.js b/src/helpers/pythonInstaller.js
index 7581f4c58..cfada9333 100644
--- a/src/helpers/pythonInstaller.js
+++ b/src/helpers/pythonInstaller.js
@@ -253,7 +253,8 @@ class PythonInstaller {
progressCallback({ stage: "Installing Python via yum...", percentage: 30 });
}
- await runCommand("sudo", ["yum", "install", "-y", "python311", "python311-pip", "python311-devel"], { timeout: TIMEOUTS.INSTALL });
+ // Note: python311-libs typically includes venv on RHEL/Fedora, but we add it explicitly for safety
+ await runCommand("sudo", ["yum", "install", "-y", "python311", "python311-pip", "python311-devel", "python311-libs"], { timeout: TIMEOUTS.INSTALL });
if (progressCallback) {
progressCallback({ stage: "Python installation complete!", percentage: 100 });
diff --git a/src/helpers/whisper.js b/src/helpers/whisper.js
index a47ab535b..ef43ac206 100644
--- a/src/helpers/whisper.js
+++ b/src/helpers/whisper.js
@@ -1013,6 +1013,24 @@ class WhisperManager {
// Clear cached Python command since we're installing new one
this.pythonCmd = null;
+ // If OPENWHISPR_PYTHON is set, skip installation and use that
+ if (process.env.OPENWHISPR_PYTHON) {
+ if (progressCallback) {
+ progressCallback({ stage: "Using custom Python override...", percentage: 50 });
+ }
+ const version = await this.getPythonVersion(process.env.OPENWHISPR_PYTHON);
+ if (!this.isPythonVersionSupported(version)) {
+ throw new Error(
+ `OPENWHISPR_PYTHON points to an invalid or unsupported Python. ` +
+ `Ensure it exists and is Python 3.x, or unset the variable.`
+ );
+ }
+ if (progressCallback) {
+ progressCallback({ stage: "Python ready", percentage: 100 });
+ }
+ return { success: true, method: "override" };
+ }
+
const bundledPython = this.resolveBundledPython();
if (bundledPython) {
if (progressCallback) {
@@ -1229,14 +1247,24 @@ class WhisperManager {
}
async installWhisper() {
- if (!process.env.OPENWHISPR_PYTHON) {
+ let pythonCmd;
+
+ if (process.env.OPENWHISPR_PYTHON) {
+ // Validate the override path before using it
+ const overridePath = process.env.OPENWHISPR_PYTHON;
+ const version = await this.getPythonVersion(overridePath);
+ if (!this.isPythonVersionSupported(version)) {
+ throw new Error(
+ `OPENWHISPR_PYTHON points to an invalid or unsupported Python: ${overridePath}. ` +
+ `Ensure it exists and is Python 3.x, or unset the variable to use the managed environment.`
+ );
+ }
+ pythonCmd = overridePath;
+ } else {
console.log("Preparing isolated Python environment...");
+ pythonCmd = await this.ensureManagedVenv();
}
- const pythonCmd = process.env.OPENWHISPR_PYTHON
- ? process.env.OPENWHISPR_PYTHON
- : await this.ensureManagedVenv();
-
// Upgrade pip inside the isolated environment to avoid resolver issues
try {
await this.upgradePip(pythonCmd);