whichcraft is a Python package that provides cross-platform and cross-Python `shutil.which` functionality. It serves as a shim for the `shutil.which` function, designed to work consistently across Python 2.7 and various Python 3 versions, including environments like Windows where system commands might behave differently. Its primary goal is to offer a reliable way to locate executables on the system PATH, similar to the Unix `which` command.
pip install whichcraftVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import the `which` function and use it to find the path to various executables. It shows successful discovery, a non-existent command returning `None`, and highlights the cross-platform behavior for common commands like 'date'.
When using `whichcraft.which` for common system commands, be aware of OS-specific differences. For commands that are shell built-ins on some platforms, `which` will return `None`. Consider using platform-agnostic Python equivalents (e.g., `datetime` module for dates) or OS-specific checks if relying on such commands.
For new projects or existing projects targeting Python 3.3+, consider using `from shutil import which` directly. Only use `whichcraft` if you need Python 2.7 compatibility or require its specific cross-platform shim for certain edge cases.
Verify if `my_command` is an actual executable file (`.exe`, `.bat`, `.cmd`) on Windows and if its directory is included in the system's PATH environment variable. If it's a shell built-in, `whichcraft` cannot locate it. For such commands, consider using `subprocess` with `shell=True` (with caution) or Python's native functionalities.
First, ensure the library is installed: `pip install whichcraft`. Second, double-check the import statement: `from whichcraft import which`. Third, if you have a file named `whichcraft.py` in your current working directory or a directory on your `PYTHONPATH`, Python might be trying to import from your local file instead of the installed package. Rename your local file or ensure it's not shadowing the package.
No dependency data recorded yet.