The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(linux): the AppImage no longer breaks every Python it starts
purple00af0c0ec8b2
diff --git a/src-tauri/src/commands/install.rs b/src-tauri/src/commands/install.rsindex 34c48d1c..7b164b52 100644--- a/src-tauri/src/commands/install.rs+++ b/src-tauri/src/commands/install.rs@@ -267,7 +267,56 @@ fn is_transient_pip_error(stderr: &str) -> bool {/// Turn raw pip stderr into a user-friendly hint with troubleshooting/// guidance. The first line of the returned string is a short diagnosis;/// the rest is the truncated original error for context.+/// "Python 3.8.10 at C:\Python38\python.exe", or just the path when the+/// interpreter will not say. Costs one process launch, which is fine on an+/// error path and is the single fact that turns "no matching wheel" from a+/// riddle into an instruction: willes0504 (Discord 2026-07-28) had a stray+/// 3.8 first in PATH and needed a volunteer plus a day to find that out.+fn interpreter_description(python_bin: &str) -> String {+ let mut cmd = Command::new(python_bin);+ cmd.arg("--version");+ #[cfg(target_os = "windows")]+ cmd.creation_flags(CREATE_NO_WINDOW);+ match cmd.output() {+ Ok(out) => {+ let text = format!(+ "{}{}",+ String::from_utf8_lossy(&out.stdout),+ String::from_utf8_lossy(&out.stderr)+ );+ let version = text.trim().lines().next().unwrap_or("").trim().to_string();+ if version.is_empty() {+ python_bin.to_string()+ } else {+ format!("{version} at {python_bin}")+ }+ }+ Err(_) => python_bin.to_string(),+ }+}+fn diagnose_pip_error(stderr: &str) -> String {+ diagnose_pip_error_for(stderr, None)+}++/// Same diagnosis, plus which interpreter produced it when the caller knows.+/// Version-shaped failures are unanswerable without that line.+fn diagnose_pip_error_for(stderr: &str, python_bin: Option<&str>) -> String {+ let base = diagnose_pip_error_inner(stderr);+ let needs_interpreter = {+ let lower = stderr.to_lowercase();+ lower.contains("could not find a version")+ || lower.contains("no matching distribution")+ || lower.contains("no module named")+ || lower.contains("modulenotfounderror")+ };+ match (needs_interpreter, python_bin) {+ (true, Some(bin)) => format!("{base}\n\nLU used {}.", interpreter_description(bin)),+ _ => base,+ }+}++fn diagnose_pip_error_inner(stderr: &str) -> String {let lower = stderr.to_lowercase();let snippet: String = stderr.chars().take(400).collect();@@ -449,14 +498,14 @@ pub fn pip_install_streaming_with_retry_cancellable(.unwrap_or_default();if !is_transient_pip_error(&last_stderr) {- return Err(diagnose_pip_error(&last_stderr));+ return Err(diagnose_pip_error_for(&last_stderr, Some(python_bin)));}}Err(format!("Exhausted {} retry attempts for transient network errors.\n\n{}",max_attempts,- diagnose_pip_error(&last_stderr)+ diagnose_pip_error_for(&last_stderr, Some(python_bin))))}@@ -3469,6 +3518,44 @@ mod tests {assert!(lower.contains("python") || lower.contains("version") || lower.contains("3.10"));}+ /// willes0504 (Discord 2026-07-28) read "ComfyUI needs Python 3.10, 3.11+ /// or 3.12" while a stray 3.8 sat first in PATH. Naming the interpreter we+ /// actually used is the difference between a riddle and an instruction.+ #[test]+ fn a_version_failure_names_the_interpreter_lu_used() {+ let msg = diagnose_pip_error_for(+ "ERROR: Could not find a version that satisfies the requirement torch (from versions: none)",+ Some("/definitely/not/a/real/python-zzz"),+ );+ assert!(msg.contains("LU used"), "got: {msg}");+ assert!(msg.contains("/definitely/not/a/real/python-zzz"), "got: {msg}");+ }++ #[test]+ fn a_missing_module_failure_also_names_the_interpreter() {+ let msg = diagnose_pip_error_for(+ "ModuleNotFoundError: No module named 'encodings'",+ Some("/definitely/not/a/real/python-zzz"),+ );+ assert!(msg.contains("LU used"), "got: {msg}");+ }++ #[test]+ fn unrelated_failures_do_not_get_an_interpreter_line() {+ // A disk-full or permission problem says nothing about the version.+ let msg = diagnose_pip_error_for(+ "OSError: [Errno 28] No space left on device",+ Some("/definitely/not/a/real/python-zzz"),+ );+ assert!(!msg.contains("LU used"), "got: {msg}");+ }++ #[test]+ fn without_an_interpreter_the_diagnosis_is_unchanged() {+ let stderr = "ERROR: Could not find a version that satisfies the requirement torch";+ assert_eq!(diagnose_pip_error(stderr), diagnose_pip_error_for(stderr, None));+ }+#[test]fn diagnose_unknown_error_falls_through_to_snippet() {let raw = "some_completely_random_error_we_haven_t_categorized";diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex a4caa9af..867de2e1 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -71,6 +71,10 @@ fn init_tracing() {fn main() {#[cfg(target_os = "linux")]apply_linux_webkit_workarounds();+ // Before anything can spawn a child: an AppImage exports PYTHONHOME and+ // PYTHONPATH into its own mount, and every python3 we start inherits them+ // and dies on "No module named 'encodings'".+ python::sanitize_appimage_python_env();init_tracing();tracing::info!(diff --git a/src-tauri/src/python.rs b/src-tauri/src/python.rsindex 1f8c8ee8..4f67a1a9 100644--- a/src-tauri/src/python.rs+++ b/src-tauri/src/python.rs@@ -7,6 +7,52 @@ use std::os::windows::process::CommandExt;#[cfg(target_os = "windows")]const CREATE_NO_WINDOW: u32 = 0x08000000;+/// True when a `PYTHONHOME` / `PYTHONPATH` value points inside an AppImage's+/// throwaway mount instead of a real Python installation.+///+/// The Linux AppImage runtime mounts itself at `/tmp/.mount_<random>` and its+/// launcher exports `PYTHONHOME` / `PYTHONPATH` into that mount. Those are+/// inherited by every process we spawn, so a system `python3` looks for its+/// standard library inside our AppImage and dies before it runs a line:+///+/// ```text+/// Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding+/// ModuleNotFoundError: No module named 'encodings'+/// PYTHONHOME = '/tmp/.mount_LocallieGkad/usr/'+/// ```+///+/// numbrain hit exactly this installing ComfyUI on Linux Mint (Discord+/// 2026-07-28) with a perfectly healthy Python 3.12, and our diagnosis sent+/// them off to reinstall Python, which of course changed nothing. No AppImage+/// user could ever install ComfyUI.+pub fn is_appimage_python_env(value: &str) -> bool {+ let v = value.trim();+ if v.is_empty() {+ return false;+ }+ // PYTHONPATH is a list; poisoned if any entry points into the mount.+ v.split(':').any(|entry| {+ let e = entry.trim();+ e.starts_with("/tmp/.mount_")+ || std::env::var("APPDIR").is_ok_and(|d| !d.is_empty() && e.starts_with(&d))+ })+}++/// Drop AppImage-injected Python variables from our own environment, so every+/// child process we spawn sees the system Python the way a shell would.+///+/// Called once at startup, before any command runs. `LD_LIBRARY_PATH` is left+/// alone on purpose: the AppImage needs it for our own bundled libraries, and+/// it was never what broke Python here.+pub fn sanitize_appimage_python_env() {+ for key in ["PYTHONHOME", "PYTHONPATH"] {+ if std::env::var(key).is_ok_and(|v| is_appimage_python_env(&v)) {+ tracing::info!(key, "dropping AppImage Python env var so child processes get a clean interpreter");+ std::env::remove_var(key);+ }+ }+}+/// Compute the path to the venv's Python interpreter for a ComfyUI install/// at `comfyui_dir`. Layout matches what `python -m venv` produces.///@@ -256,6 +302,40 @@ mod tests {use super::*;use std::fs;+ // ── AppImage Python env poisoning (numbrain, Discord 2026-07-28) ────────++ /// The exact values from the failing install on Linux Mint. Our own+ /// AppImage mount, inherited by the python3 we spawn, which then cannot+ /// find its standard library.+ #[test]+ fn appimage_mount_paths_are_recognised() {+ assert!(is_appimage_python_env("/tmp/.mount_LocallieGkad/usr/"));+ assert!(is_appimage_python_env("/tmp/.mount_LocallieGkad/usr/share/pyshared/:"));+ assert!(is_appimage_python_env("/tmp/.mount_ABC123/usr/lib/python3.12"));+ }++ #[test]+ fn a_poisoned_entry_anywhere_in_the_list_counts() {+ // PYTHONPATH is colon-separated; one bad entry breaks the interpreter.+ assert!(is_appimage_python_env("/home/u/mylib:/tmp/.mount_XY/usr/share/pyshared/"));+ }++ #[test]+ fn real_python_installs_are_left_alone() {+ assert!(!is_appimage_python_env("/usr/lib/python3.12"));+ assert!(!is_appimage_python_env("/home/user/.local/lib/python3.12"));+ assert!(!is_appimage_python_env("/opt/python3.11"));+ assert!(!is_appimage_python_env("C:\\Python312"));+ // A user's own directory that merely lives under /tmp is not a mount.+ assert!(!is_appimage_python_env("/tmp/my-python-experiment"));+ }++ #[test]+ fn empty_and_whitespace_are_not_poisoned() {+ assert!(!is_appimage_python_env(""));+ assert!(!is_appimage_python_env(" "));+ }+// ── venv_python_path layout (Bug E — Arch PEP 668 venv) ─────────────────#[test]