discover python executable
MODIFY
Cargo.toml
Cargo.toml
@@ -32,6 +32,7 @@ once_cell = "1.0"
pkg-config = "0.3"
rayon = "1.0"
semver = "0.9"
+which_crate = {package = "which", version = "3.0", default-features = false}
[dev-dependencies]
matches = "0.1"

MODIFY
README.md
README.md
@@ -118,16 +118,25 @@ export LD_LIBRARY_PATH=/custom/prefix/lib/
Path specified by `PKG_CONFIG_PATH` must contain `opencv.pc` or `opencv4.pc` (for OpenCV 4.x).
Path specified by `LD_LIBRARY_PATH` must contain `libopencv_*.so` files.
+### Environment variables
+
+* `OPENCV_HEADER_DIR`
During crate build it uses opencv headers supplied inside the crate for binding generation.
If you want to use your own (system) headers supply `OPENCV_HEADER_DIR` environment variable.
The directory in that environment variable should contain `opencv2` dir, e.g. `/usr/include` for
OpenCV-3.4.x or `/usr/include/opencv4` for OpenCV-4.x. Please be sure to match the supplied
header version with the crate version features (opencv-34, opencv-41, etc.).
+* `OPENCV_PKGCONFIG_NAME`
In some cases you might want to override the pkgconfig package name, you can use `OPENCV_PKGCONFIG_NAME`
environment variable for that. If you set it pkgconfig will expect to find the file with that name
and `.pc` extension in the package directory.
+* `OPENCV_PYTHON3_BIN`
+ During the build crate uses Python 3 to run header parsing and generation. The binary is usually
+ autodiscovered, but you can use `OPENCV_PYTHON3_BIN` to specify the full path to the binary to
+ invoke. E.g. "/usr/bin/python3" or "C:\Python37\python.exe"
+
### Compiling OpenCV
See the [upstream

MODIFY
build.rs
build.rs
@@ -15,6 +15,7 @@ use rayon::prelude::*;
use semver::{Version, VersionReq};
use glob_crate::glob;
+use which_crate::which;
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
@@ -305,7 +306,13 @@ fn build_wrapper(opencv_header_dir: &PathBuf) -> Result<()> {
unreachable!();
};
modules.par_iter().for_each(|(module, files)| {
- if !Command::new("python3")
+ let python3 = env::var_os("OPENCV_PYTHON3_BIN")
+ .map(PathBuf::from)
+ .or_else(|| which("python3").ok())
+ .or_else(|| which("python").ok())
+ .unwrap_or_else(|| PathBuf::from("python3"));
+ // todo ensure that this is actually python3 (e.g. run --version)
+ if !Command::new(python3)
.args(&["-B", "gen_rust.py", "hdr_parser.py", out_dir_as_str, out_dir_as_str, module, &version])
.args(
files.iter()

discover python executable