diff --git a/src/modules/python.rs b/src/modules/python.rs index fdab440e..f19da350 100644 --- a/src/modules/python.rs +++ b/src/modules/python.rs @@ -46,7 +46,18 @@ pub fn segment(context: &Context) -> Option { fn get_python_version() -> Option { match Command::new("python").arg("--version").output() { - Ok(output) => Some(String::from_utf8(output.stdout).unwrap()), + Ok(output) => { + // We have to check both stdout and stderr since for Python versions + // < 3.4, Python reports to stderr and for Python version >= 3.5, + // Python reports to stdout + if output.stdout.is_empty() { + let stderr_string = String::from_utf8(output.stderr).unwrap(); + Some(stderr_string) + } else { + let stdout_string = String::from_utf8(output.stdout).unwrap(); + Some(stdout_string) + } + } Err(_) => None, } }