Skip to content

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.

fix(trainer): reject a 32-bit or ARM64 Python and name path+version in the error

purple4a3ba7a0613a
diff --git a/src-tauri/src/commands/trainer.rs b/src-tauri/src/commands/trainer.rs
index efd9f549..7e1dc229 100644
--- a/src-tauri/src/commands/trainer.rs
+++ b/src-tauri/src/commands/trainer.rs
@@ -1208,11 +1208,22 @@ pub(crate) fn venv_create_args(action: VenvAction) -> &'static [&'static str] {
/// Python is deliberately not the pointer: it short-circuits as soon as any
/// Python exists, which on a 3.14 machine is exactly the one that cannot help.
/// The last sentence is the marker `already_explained` looks for.
-pub(crate) fn no_trainer_python_message(found: &[String], os: &str, winget_tried: bool) -> String {
+///
+/// K4, 2026-09-18: `found` used to be versions alone, so the message named
+/// what version was on the machine but not where LU looked or which install
+/// it was reading. gekiritz's rebuild loop (see `python_version_and_arch`)
+/// is exactly the case where two Pythons report the same version and only
+/// one of them is real — the path is what lets the customer, or us reading a
+/// Discord paste, tell which is which.
+pub(crate) fn no_trainer_python_message(found: &[(String, String)], os: &str, winget_tried: bool) -> String {
let have = if found.is_empty() {
"no Python that starts".to_string()
} else {
- format!("Python {}", found.join(" and "))
+ found
+ .iter()
+ .map(|(path, version)| format!("Python {version} at {path}"))
+ .collect::<Vec<_>>()
+ .join(" and ")
};
let get = match os {
"windows" if winget_tried => {
@@ -1245,6 +1256,23 @@ fn trainer_base_python(
if !crate::python::is_real_python(&p) || seen.iter().any(|(s, _)| s.eq_ignore_ascii_case(&p)) {
continue;
}
+ // K4: a 32-bit or ARM64 Python answers `sys.version_info` exactly
+ // like a normal one, builds a venv that looks complete, and only
+ // dies once pip resolves torch — which reports as the wrong
+ // Python-version message and sends the customer back to the same
+ // interpreter. Excluding it here, before the venv is ever built,
+ // is what makes the retry pick a different one instead of
+ // looping (gekiritz, Discord 2026-09-16).
+ #[cfg(target_os = "windows")]
+ match crate::python::python_version_and_arch(&p) {
+ Some((v, true)) => seen.push((p, v)),
+ Some((v, false)) => push_log(
+ state,
+ &format!("Skipping {p} (Python {v}): not a 64-bit x86 build, the trainer's PyTorch wheels do not exist for it."),
+ ),
+ None => {}
+ }
+ #[cfg(not(target_os = "windows"))]
if let Some(v) = crate::python::python_version(&p) {
seen.push((p, v));
}
@@ -1273,9 +1301,8 @@ fn trainer_base_python(
// that matters, the interpreter on disk is.
found = survey();
}
- let versions: Vec<String> = found.iter().map(|(_, v)| v.clone()).collect();
let (path, version) = choose_trainer_python(&found)
- .ok_or_else(|| no_trainer_python_message(&versions, std::env::consts::OS, winget_tried))?;
+ .ok_or_else(|| no_trainer_python_message(&found, std::env::consts::OS, winget_tried))?;
if path != python_bin {
let default = found
.first()
@@ -2980,10 +3007,12 @@ mod shutdown_tests {
#[test]
fn when_no_python_fits_the_message_names_what_is_there_and_where_to_get_one() {
use super::{install_failed_message, no_trainer_python_message, repair_aborted_message, Preflight};
- let found = vec!["3.14.6".to_string()];
+ let found = vec![("C:\\Python314\\python.exe".to_string(), "3.14.6".to_string())];
let win = no_trainer_python_message(&found, "windows", true);
assert!(win.contains("3.10, 3.11 or 3.12"), "{win}");
assert!(win.contains("has Python 3.14.6"), "{win}");
+ // K4: the path is what tells two same-version Pythons apart.
+ assert!(win.contains("at C:\\Python314\\python.exe"), "{win}");
assert!(win.contains("winget") && win.contains("python.org/downloads/windows"), "{win}");
assert!(win.contains("Set up trainer"), "{win}");
// Settings > Install Python short-circuits as soon as ANY Python exists,
@@ -3131,7 +3160,7 @@ mod shutdown_tests {
#[test]
fn an_error_that_already_names_its_button_is_left_alone() {
use super::{install_failed_message, no_trainer_python_message, repair_aborted_message, Preflight};
- let eigen = no_trainer_python_message(&["3.14.6".to_string()], "windows", false);
+ let eigen = no_trainer_python_message(&[("C:\\Python314\\python.exe".to_string(), "3.14.6".to_string())], "windows", false);
assert_eq!(install_failed_message(&eigen), eigen);
assert_eq!(
repair_aborted_message(&Preflight::TorchBroken("x".into()), &eigen),
@@ -3562,7 +3591,7 @@ mod journey_tests {
// The sentence names the versions, and the range is the one musubi and
// the wheels agree on.
assert_eq!(TRAINER_PYTHON_RANGE, "3.10, 3.11 or 3.12");
- let msg = no_trainer_python_message(&["3.14.6".to_string()], "windows", false);
+ let msg = no_trainer_python_message(&[("C:\\Python314\\python.exe".to_string(), "3.14.6".to_string())], "windows", false);
assert!(msg.contains("3.10, 3.11 or 3.12"), "{msg}");
assert!(msg.contains("3.14.6"), "the message names what is on the machine: {msg}");
assert!(!trainer_supports_python("3.13.0") && !trainer_supports_python("3.14.6"));
diff --git a/src-tauri/src/python.rs b/src-tauri/src/python.rs
index 54f88f15..3ff1ceb3 100644
--- a/src-tauri/src/python.rs
+++ b/src-tauri/src/python.rs
@@ -414,6 +414,55 @@ pub fn python_version(exe: &str) -> Option<String> {
if v.is_empty() { None } else { Some(v) }
}
+/// True for a 64-bit x86 interpreter, the only architecture PyTorch's Windows
+/// CUDA wheels exist for. `bits` is `struct.calcsize('P') * 8`, which is what
+/// actually answers "32-bit or 64-bit": a 32-bit interpreter running under
+/// WOW64 on a 64-bit Windows still reports `platform.machine() == "AMD64"`,
+/// because that reads the OS, not the process. `machine` is
+/// `platform.machine()`, which is what actually answers "x86 or ARM": a
+/// native ARM64 interpreter is genuinely 64-bit, and torch still has no
+/// Windows wheel for it. Both have to agree.
+#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
+pub fn is_trainer_arch(bits: u32, machine: &str) -> bool {
+ bits == 64 && machine.eq_ignore_ascii_case("AMD64")
+}
+
+/// [`python_version`] plus [`is_trainer_arch`] in one process spawn.
+///
+/// gekiritz (Discord, 2026-09-16): "Set up trainer" kept reporting "the
+/// Python in the trainer environment ... needs 3.10, 3.11 or 3.12", rebuilt
+/// on request, and kept failing the same way. `python_version` alone cannot
+/// see why: it only reads `sys.version_info`, which a 32-bit or ARM64 Python
+/// 3.11/3.12 answers exactly like a normal one. Such an interpreter passes
+/// every check `trainer_base_python` runs, builds a venv that looks complete,
+/// and only dies once pip actually resolves torch, with "Could not find a
+/// version that satisfies the requirement torch" — which `pip_failure_kind`
+/// reads as `NoMatchingWheel` and reports as the wrong-Python-version
+/// message. The version was never the problem, so the button that message
+/// points at chose the same interpreter again on every retry.
+#[cfg(target_os = "windows")]
+pub fn python_version_and_arch(exe: &str) -> Option<(String, bool)> {
+ let out = python_command(exe)
+ .args([
+ "-c",
+ "import struct,platform;print('%d.%d.%d'%__import__('sys').version_info[:3]);print(struct.calcsize('P')*8);print(platform.machine())",
+ ])
+ .output()
+ .ok()?;
+ if !out.status.success() {
+ return None;
+ }
+ let text = String::from_utf8_lossy(&out.stdout);
+ let mut lines = text.lines();
+ let version = lines.next().unwrap_or("").trim().to_string();
+ let bits: u32 = lines.next().and_then(|l| l.trim().parse().ok()).unwrap_or(0);
+ let machine = lines.next().unwrap_or("").trim().to_string();
+ if version.is_empty() {
+ return None;
+ }
+ Some((version, is_trainer_arch(bits, &machine)))
+}
+
/// Every interpreter this machine has, LU's usual order, duplicates and the
/// Store stub dropped. `get_python_bin` answers "which Python does LU use";
/// a lane whose wheels stop at a version has to ask "which Pythons are
@@ -885,6 +934,32 @@ mod tests {
let _ = fs::remove_dir_all(&tmp);
}
+ // ── K4: a 64-bit interpreter can still be the wrong architecture ────────
+ // (gekiritz, Discord 2026-09-16: a 3.11/3.12 that passes every version
+ // check and still cannot install torch).
+
+ #[test]
+ fn a_64_bit_x86_interpreter_is_the_only_one_the_trainer_wants() {
+ assert!(is_trainer_arch(64, "AMD64"));
+ // platform.machine() case varies by Python build; the check must not.
+ assert!(is_trainer_arch(64, "amd64"));
+ }
+
+ #[test]
+ fn a_native_arm64_interpreter_is_64_bit_and_still_wrong() {
+ // The pointer-size check alone would let this through: ARM64 Windows
+ // Python is genuinely 64-bit, torch just has no wheel for it.
+ assert!(!is_trainer_arch(64, "ARM64"));
+ }
+
+ #[test]
+ fn a_32_bit_interpreter_is_wrong_even_when_wow64_says_amd64() {
+ // A 32-bit interpreter on 64-bit Windows still reports
+ // platform.machine() == "AMD64" (that reads the OS, not the
+ // process) — struct.calcsize('P') is the one that catches it.
+ assert!(!is_trainer_arch(32, "AMD64"));
+ }
+
// ── the launcher registry, read for a lane that needs a versioned Python ─
//
// `py -0p` is the one list on Windows that names every python.org install