Find Executable
Find Executable (find-exe) is a Python library and command-line interface designed to locate matching executables on a system given certain criteria. It provides a robust way to programmatically find executables, similar to the `which` or `where` commands, with additional flexibility. The current version is 0.2.1, and it maintains an active release cadence with minor updates and fixes.
Common errors
-
find_exe.which('my_executable') returns None unexpectedlycause The specified executable is either not in the system's PATH, not in the custom `paths` provided, or lacks execute permissions for the current user. On Windows, it might also be due to an unrecognized file extension (not in PATHEXT).fixVerify the executable's location and permissions. If it's not in a standard PATH directory, use the `paths` argument: `find_exe.which('my_executable', paths=['/path/to/dir'])`. For Windows, ensure the executable's extension (e.g., '.exe', '.bat') is included in your system's `PATHEXT` variable or that you specify the full executable name including extension. -
TypeError: which() got an unexpected keyword argument 'paths'
cause The `paths` argument was introduced in version 0.2.0. This error indicates you are using an older version of `find-exe`.fixUpgrade your `find-exe` library to version 0.2.0 or newer: `pip install --upgrade find-exe`.
Warnings
- gotcha Prior to version 0.2.1, `find-exe` could experience case sensitivity issues on Windows, especially when the `PATHEXT` environment variable was explicitly defined. This could lead to executables not being found or unexpected results.
- gotcha When using `find_exe.which()` or `find_exe.with_prefix()` on Windows, the order of directories in your system's `PATH` environment variable and the values in `PATHEXT` (file extensions to consider as executables) significantly influence the results. Be aware that the behavior might differ from Linux/macOS systems or even from Windows' native `where` command if `PATHEXT` is customized or incomplete.
Install
-
pip install find-exe
Imports
- find_exe
import find_exe
Quickstart
import find_exe
# Find 'python' executable in the system's PATH
python_exe = find_exe.which('python')
print(f"Python executable: {python_exe}")
# Find executables starting with 'py'
# Note: This might return different paths depending on your system configuration.
py_executables = find_exe.with_prefix('py')
print(f"Executables with prefix 'py': {py_executables[:3]}...")
# Find a specific executable in custom paths
custom_paths = ['/usr/local/bin', '/opt/some_app/bin'] # Example paths
git_exe_custom = find_exe.which('git', paths=custom_paths)
print(f"Git executable in custom paths: {git_exe_custom}")