fn find_all_windows(target: &Target) -> Result<Vec<String>> {
    let code = "import sys; print(sys.executable or '')";
    let mut interpreter = vec![];
    let mut versions_found = HashSet::new();

    // If Python is installed from Python.org it should include the "python launcher"
    // which is used to find the installed interpreters
    let execution = Command::new("py").arg("-0").output();
    if let Ok(output) = execution {
        let expr = Regex::new(r" -(\d).(\d)-(\d+)(?: .*)?").unwrap();
        let lines = str::from_utf8(&output.stdout).unwrap().lines();
        for line in lines {
            if let Some(capture) = expr.captures(line) {
                let context = "Expected a digit";

                let major = capture
                    .get(1)
                    .unwrap()
                    .as_str()
                    .parse::<usize>()
                    .context(context)?;
                let minor = capture
                    .get(2)
                    .unwrap()
                    .as_str()
                    .parse::<usize>()
                    .context(context)?;
                if !versions_found.contains(&(major, minor)) {
                    let pointer_width = capture
                        .get(3)
                        .unwrap()
                        .as_str()
                        .parse::<usize>()
                        .context(context)?;

                    if windows_interpreter_no_build(
                        major,
                        minor,
                        target.pointer_width(),
                        pointer_width,
                    ) {
                        continue;
                    }

                    let version = format!("-{}.{}-{}", major, minor, pointer_width);

                    let output = Command::new("py")
                        .args(&[&version, "-c", code])
                        .output()
                        .unwrap();
                    let path = str::from_utf8(&output.stdout).unwrap().trim();
                    if !output.status.success() || path.trim().is_empty() {
                        bail!("Couldn't determine the path to python for `py {}`", version);
                    }
                    interpreter.push(path.to_string());
                    versions_found.insert((major, minor));
                }
            }
        }
    }

    // Conda environments are also supported on windows
    let conda_info = Command::new("conda").arg("info").arg("-e").output();
    if let Ok(output) = conda_info {
        let lines = str::from_utf8(&output.stdout).unwrap().lines();
        // The regex has three parts: The first matches the name and skips
        // comments, the second skips the part in between and the third
        // extracts the path
        let re = Regex::new(r"^([^#].*?)[\s*]+([\w\\:.-]+)\s*$").unwrap();
        let mut paths = vec![];
        for i in lines {
            if let Some(capture) = re.captures(&i) {
                if &capture[1] == "base" {
                    continue;
                }
                paths.push(String::from(&capture[2]));
            }
        }

        for path in paths {
            let executable = Path::new(&path).join("python");
            let python_info = Command::new(&executable)
                .arg("-c")
                .arg("import sys; print(sys.version)")
                .output();

            let python_info = match python_info {
                Ok(python_info) => python_info,
                Err(err) => {
                    if err.kind() == io::ErrorKind::NotFound {
                        // This conda env doesn't have python installed
                        continue;
                    } else {
                        bail!(
                            "Error getting Python version info from conda env at {}",
                            path
                        );
                    }
                }
            };

            let version_info = str::from_utf8(&python_info.stdout).unwrap();
            let expr = Regex::new(r"(\d).(\d).(\d+)").unwrap();
            if let Some(capture) = expr.captures(version_info) {
                let major = capture.get(1).unwrap().as_str().parse::<usize>().unwrap();
                let minor = capture.get(2).unwrap().as_str().parse::<usize>().unwrap();
                if !versions_found.contains(&(major, minor)) {
                    let pointer_width = if version_info.contains("64 bit (AMD64)") {
                        64_usize
                    } else {
                        32_usize
                    };

                    if windows_interpreter_no_build(
                        major,
                        minor,
                        target.pointer_width(),
                        pointer_width,
                    ) {
                        continue;
                    }

                    interpreter.push(String::from(executable.to_str().unwrap()));
                    versions_found.insert((major, minor));
                }
            }
        }
    }
    if interpreter.is_empty() {
        bail!(
            "Could not find any interpreters, are you sure you have python installed on your PATH?"
        );
    };
    Ok(interpreter)
}
/// On windows regular Python installs are supported along with environments
/// being managed by `conda`.
///
/// We can't use the linux trick with trying different binary names since on
/// windows the binary is always called "python.exe".  However, whether dealing
/// with regular Python installs or `conda` environments there are tools we can
/// use to query the information regarding installed interpreters.
///
/// Regular Python installs downloaded from Python.org will include the python
/// launcher by default.  We can use the launcher to find the information we need
/// for each installed interpreter using `py -0` which produces something like
/// the following output (the path can by determined using `sys.executable`):
///
/// ```bash
/// Installed Pythons found by py Launcher for Windows
/// -3.7-64 *
/// -3.6-32
/// ```
///
/// When using `conda` we can use the `conda info -e` command to retrieve information
/// regarding the installed interpreters being managed by `conda`.  This is an example
/// of the output expected:
///
/// ```bash
/// # conda environments:
/// #
/// base                     C:\Users\<user-name>\Anaconda3
/// foo1                  *  C:\Users\<user-name>\Anaconda3\envs\foo1
/// foo2                  *  C:\Users\<user-name>\Anaconda3\envs\foo2
/// ```
///
/// The information required can either by obtained by parsing this output directly or
/// by invoking the interpreters to obtain the information.
///
/// As well as the version numbers, etc. of the interpreters we also have to find the
/// pointer width to make sure that the pointer width (32-bit or 64-bit) matches across
/// platforms.
On windows regular Python installs are supported along with environments
being managed by `conda`.

We can't use the linux trick with trying different binary names since on
windows the binary is always called "python.exe".  However, whether dealing
with regular Python installs or `conda` environments there are tools we can
use to query the information regarding installed interpreters.

Regular Python installs downloaded from Python.org will include the python
launcher by default.  We can use the launcher to find the information we need
for each installed interpreter using `py -0` which produces something like
the following output (the path can by determined using `sys.executable`).






On windows regular Python installs are supported along with environments being managed by ` conda ` . We can ' t use the linux trick with trying different binary names since on windows the binary is always called " python . exe " . However whether dealing with regular Python installs or ` conda ` environments there are tools we can use to query the information regarding installed interpreters . Regular Python installs downloaded from Python . org will include the python launcher by default . We can use the launcher to find the information we need for each installed interpreter using ` py - 0 ` which produces something like the following output ( the path can by determined using ` sys . executable ` ) .
fn find_all_windows(target: &Target) -> Result<Vec<String>> {
    let code = "import sys; print(sys.executable or '')";
    let mut interpreter = vec![];
    let mut versions_found = HashSet::new();
    // If Python is installed from Python.org it should include the "python launcher"
    // which is used to find the installed interpreters
    let execution = Command::new("py").arg("-0").output();
    if let Ok(output) = execution {
        let expr = Regex::new(r" -(\d).(\d)-(\d+)(?: .*)?").unwrap();
        let lines = str::from_utf8(&output.stdout).unwrap().lines();
        for line in lines {
            if let Some(capture) = expr.captures(line) {
                let context = "Expected a digit";
                let major = capture
                    .get(1)
                    .unwrap()
                    .as_str()
                    .parse::<usize>()
                    .context(context)?;
                let minor = capture
                    .get(2)
                    .unwrap()
                    .as_str()
                    .parse::<usize>()
                    .context(context)?;
                if !versions_found.contains(&(major, minor)) {
                    let pointer_width = capture
                        .get(3)
                        .unwrap()
                        .as_str()
                        .parse::<usize>()
                        .context(context)?;
                    if windows_interpreter_no_build(
                        major,
                        minor,
                        target.pointer_width(),
                        pointer_width,
                    ) {
                        continue;
                    }
                    let version = format!("-{}.{}-{}", major, minor, pointer_width);
                    let output = Command::new("py")
                        .args(&[&version, "-c", code])
                        .output()
                        .unwrap();
                    let path = str::from_utf8(&output.stdout).unwrap().trim();
                    if !output.status.success() || path.trim().is_empty() {
                        bail!("Couldn't determine the path to python for `py {}`", version);
                    }
                    interpreter.push(path.to_string());
                    versions_found.insert((major, minor));
                }
            }
        }
    }
    // Conda environments are also supported on windows
    let conda_info = Command::new("conda").arg("info").arg("-e").output();
    if let Ok(output) = conda_info {
        let lines = str::from_utf8(&output.stdout).unwrap().lines();
        // The regex has three parts: The first matches the name and skips
        // comments, the second skips the part in between and the third
        // extracts the path
        let re = Regex::new(r"^([^#].*?)[\s*]+([\w\\:.-]+)\s*$").unwrap();
        let mut paths = vec![];
        for i in lines {
            if let Some(capture) = re.captures(&i) {
                if &capture[1] == "base" {
                    continue;
                }
                paths.push(String::from(&capture[2]));
            }
        }
        for path in paths {
            let executable = Path::new(&path).join("python");
            let python_info = Command::new(&executable)
                .arg("-c")
                .arg("import sys; print(sys.version)")
                .output();
            let python_info = match python_info {
                Ok(python_info) => python_info,
                Err(err) => {
                    if err.kind() == io::ErrorKind::NotFound {
                        // This conda env doesn't have python installed
                        continue;
                    } else {
                        bail!(
                            "Error getting Python version info from conda env at {}",
                            path
                        );
                    }
                }
            };
            let version_info = str::from_utf8(&python_info.stdout).unwrap();
            let expr = Regex::new(r"(\d).(\d).(\d+)").unwrap();
            if let Some(capture) = expr.captures(version_info) {
                let major = capture.get(1).unwrap().as_str().parse::<usize>().unwrap();
                let minor = capture.get(2).unwrap().as_str().parse::<usize>().unwrap();
                if !versions_found.contains(&(major, minor)) {
                    let pointer_width = if version_info.contains("64 bit (AMD64)") {
                        64_usize
                    } else {
                        32_usize
                    };
                    if windows_interpreter_no_build(
                        major,
                        minor,
                        target.pointer_width(),
                        pointer_width,
                    ) {
                        continue;
                    }
                    interpreter.push(String::from(executable.to_str().unwrap()));
                    versions_found.insert((major, minor));
                }
            }
        }
    }
    if interpreter.is_empty() {
        bail!(
            "Could not find any interpreters, are you sure you have python installed on your PATH?"
        );
    };
    Ok(interpreter)
}
fn find_all_windows ( target : & Target ) -> Result < Vec < String > > { let code = " " ; let mut interpreter = vec ! [ ] ; let mut versions_found = HashSet :: new ( ) ; // If Python is installed from Python.org it should include the "python launcher" // which is used to find the installed interpreters let execution = Command :: new ( " " ) . arg ( " " ) . output ( ) ; if let Ok ( output ) = execution { let expr = Regex :: new ( r" -(\d).(\d)-(\d+)(?: .*)?" ) . unwrap ( ) ; let lines = str :: from_utf8 ( & output . stdout ) . unwrap ( ) . lines ( ) ; for line in lines { if let Some ( capture ) = expr . captures ( line ) { let context = " " ; let major = capture . get ( 1 ) . unwrap ( ) . as_str ( ) . parse :: < usize > ( ) . context ( context ) ? ; let minor = capture . get ( 2 ) . unwrap ( ) . as_str ( ) . parse :: < usize > ( ) . context ( context ) ? ; if ! versions_found . contains ( & ( major , minor ) ) { let pointer_width = capture . get ( 3 ) . unwrap ( ) . as_str ( ) . parse :: < usize > ( ) . context ( context ) ? ; if windows_interpreter_no_build ( major , minor , target . pointer_width ( ) , pointer_width , ) { continue ; } let version = format ! ( " " major minor pointer_width ) ; let output = Command :: new ( " " ) . args ( & [ & version , " " , code ] ) . output ( ) . unwrap ( ) ; let path = str :: from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ; if ! output . status . success ( ) || path . trim ( ) . is_empty ( ) { bail ! ( " " version ) ; } interpreter . push ( path . to_string ( ) ) ; versions_found . insert ( ( major , minor ) ) ; } } } } // Conda environments are also supported on windows let conda_info = Command :: new ( " " ) . arg ( " " ) . arg ( " " ) . output ( ) ; if let Ok ( output ) = conda_info { let lines = str :: from_utf8 ( & output . stdout ) . unwrap ( ) . lines ( ) ; // The regex has three parts: The first matches the name and skips // comments, the second skips the part in between and the third // extracts the path let re = Regex :: new ( r"^([^#].*?)[\s*]+([\w\\:.-]+)\s*$" ) . unwrap ( ) ; let mut paths = vec ! [ ] ; for i in lines { if let Some ( capture ) = re . captures ( & i ) { if & capture [ 1 ] == " " { continue ; } paths . push ( String :: from ( & capture [ 2 ] ) ) ; } } for path in paths { let executable = Path :: new ( & path ) . join ( " " ) ; let python_info = Command :: new ( & executable ) . arg ( " " ) . arg ( " " ) . output ( ) ; let python_info = match python_info { Ok ( python_info ) => python_info , Err ( err ) => { if err . kind ( ) == io :: ErrorKind :: NotFound { // This conda env doesn't have python installed continue ; } else { bail ! ( " " path ) ; } } } ; let version_info = str :: from_utf8 ( & python_info . stdout ) . unwrap ( ) ; let expr = Regex :: new ( r"(\d).(\d).(\d+)" ) . unwrap ( ) ; if let Some ( capture ) = expr . captures ( version_info ) { let major = capture . get ( 1 ) . unwrap ( ) . as_str ( ) . parse :: < usize > ( ) . unwrap ( ) ; let minor = capture . get ( 2 ) . unwrap ( ) . as_str ( ) . parse :: < usize > ( ) . unwrap ( ) ; if ! versions_found . contains ( & ( major , minor ) ) { let pointer_width = if version_info . contains ( " " ) { 64_usize } else { 32_usize } ; if windows_interpreter_no_build ( major , minor , target . pointer_width ( ) , pointer_width , ) { continue ; } interpreter . push ( String :: from ( executable . to_str ( ) . unwrap ( ) ) ) ; versions_found . insert ( ( major , minor ) ) ; } } } } if interpreter . is_empty ( ) { bail ! ( " " ) ; } ; Ok ( interpreter ) }
On windows regular Python installs are supported along with environments
being managed by `conda`.
On windows regular Python installs are supported along with environments being managed by ` conda ` .
target
&Target
target
&Target
conda environments:
base                     C:\Users\\Anaconda3
foo1                  *  C:\Users\\Anaconda3\envs\foo1
foo2                  *  C:\Users\\Anaconda3\envs\foo2
```

The information required can either by obtained by parsing this output directly or
by invoking the interpreters to obtain the information.

As well as the version numbers, etc. of the interpreters we also have to find the
pointer width to make sure that the pointer width (32-bit or 64-bit) matches across
platforms.
base C : \ Users \\ Anaconda3 foo1 * C : \ Users \\ Anaconda3 \ envs \ foo1 foo2 * C : \ Users \\ Anaconda3 \ envs \ foo2 ` ` ` The information required can either by obtained by parsing this output directly or by invoking the interpreters to obtain the information . As well as the version numbers etc . of the interpreters we also have to find the pointer width to make sure that the pointer width ( 32 - bit or 64 - bit ) matches across platforms .