Crates.io | findpython |
lib.rs | findpython |
version | 1.0.0-alpha.3 |
source | src |
created_at | 2023-07-10 10:05:43.884877 |
updated_at | 2023-07-12 08:32:05.660695 |
description | Find python executables on your system |
homepage | |
repository | https://github.com/frostming/findpython |
max_upload_size | |
id | 912784 |
size | 80,871 |
A utility to find python versions on your system.
This library is a rewrite of pythonfinder project by @techalchemy. It simplifies the whole code structure while preserving most of the original features.
FindPython can be used in both Python and Rust projects.
To install FindPython in Python:
pip install findpython
To install FindPython in Rust:
cargo install findpyhton
Or use FindPython library in a Rust project:
cargo add findpython
>>> import findpython
>>> findpython.find(3, 9) # Find by major and minor version
<PythonVersion executable=/opt/homebrew/bin/python3.9, version=3.9.17, arch=64bit>
>>> findpython.find("3.9") # Find by version string
<PythonVersion executable=/opt/homebrew/bin/python3.9, version=3.9.17, arch=64bit>
>>> findpython.find("3.9-32") # Find by version string and architecture
<PythonVersion executable=C:/Python/3.9-32/python.exe, version=3.9.10, arch=32bit>
>>> findpython.find(name="python3") # Find by executable name
<PythonVersion executable=/Users/fming/wkspace/github/findpython/.venv/bin/python3, version=3.11.4, arch=64bit>
>>> findpython.find("python3") # Find by executable name without keyword argument, same as above
<PythonVersion executable=/Users/fming/wkspace/github/findpython/.venv/bin/python3, version=3.11.4, arch=64bit>
>>> findpython.find_all(major=3, minor=9) # Same arguments as `find()`, but return all matches
[<PythonVersion executable=/opt/homebrew/bin/python3.9, version=3.9.17, arch=64bit>,
<PythonVersion executable=/usr/bin/python3, version=3.9.6, arch=64bit>]
use findpython::{Finder, MatchOptions};
fn main() {
let finder = Finder::default();
// Find by major and minor version
let py = finder.find(MatchOptions::default().major(3).minor(10)).unwrap();
println!("{:?}", py);
// Find all matches
let all_pythons = finder.find_all();
println!("{:?}", all_pythons);
}
In addition, FindPython provides a CLI interface to find python versions:
Find python executables on your system
Usage: findpython [OPTIONS] [VERSION_SPEC]
Arguments:
[VERSION_SPEC] The version spec to find, e.g. 3|3.8|python3
Options:
-a, --all Return all matching Python versions
--resolve-symlinks Resolve symlinks and remove duplicate results
--no-same-file Remove duplicate results that are the same binary
--no-same-python Remove duplicate results that wrap the same Python interpreter
--providers <PROVIDERS> Select provider names(comma-separated) to use
-o, --output <OUTPUT> The output format [default: default] [possible values: default, json, path]
-h, --help Print help
-V, --version Print version
FindPython finds Python from the following places:
PATH
environment variableFindPython is released under MIT License.