check python interpreter by --version

This commit is contained in:
namuyan 2019-10-12 11:23:27 +09:00
parent 89b7c7e309
commit 5d19b9124a
1 changed files with 6 additions and 3 deletions

View File

@ -25,10 +25,13 @@ const MIN_VERSION: &'static str = "1.37.0-nightly";
lazy_static! {
static ref PYTHON_INTERPRETER: &'static str = {
["python3", "python"]
["python", "python3"]
.iter()
.map(|bin| (bin, Command::new(bin).spawn()))
.find(|(_, r)| r.is_ok())
.map(|bin| (bin, Command::new(bin).arg("--version").output()))
.filter(|(_, r)| r.is_ok())
.map(|(bin, r)| (bin, r.unwrap().stderr))
// begin with `Python 3.X.X :: additional info`
.find(|(_, r)| r.starts_with(b"Python 3"))
.map(|(bin, _)| bin)
.expect("Python 3.x interpreter not found")
};