{"id":7864,"library":"whichcraft","title":"whichcraft","description":"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.","status":"maintenance","version":"0.6.1","language":"en","source_language":"en","source_url":"https://github.com/pydanny/whichcraft","tags":["system","path","utility","shutil","cross-platform"],"install":[{"cmd":"pip install whichcraft","lang":"bash","label":"Install stable release"}],"dependencies":[],"imports":[{"symbol":"which","correct":"from whichcraft import which"}],"quickstart":{"code":"from whichcraft import which\n\n# Find the path to a common executable\npython_path = which('python')\nprint(f\"Python executable found at: {python_path}\")\n\n# Try to find a command that might not exist\nnon_existent_command = which('nonexistent_command_123')\nprint(f\"Non-existent command found at: {non_existent_command}\")\n\n# Example of a command that might behave differently across OS (e.g., 'date')\ndate_command = which('date')\nprint(f\"'date' command found at: {date_command}\")","lang":"python","description":"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'."},"warnings":[{"fix":"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.","message":"The behavior of `whichcraft.which('date')` (or similar internal system commands) differs between Windows and Unix-like systems. On Unix-like systems (Linux, macOS), `date` is typically a standalone executable returning its path. On Windows, `date` is often an internal shell command (cmd.exe built-in) and thus `whichcraft.which` will return `None`, as it only searches for external executables on the PATH.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"For Python 3.3 and newer, the functionality provided by `whichcraft` is natively available in the standard library as `shutil.which`. While `whichcraft` still works, it may not be necessary for projects targeting only modern Python 3 versions, as its primary value was cross-version (Python 2.7 and Python 3.x) compatibility and Windows support for older Python 3 versions.","severity":"deprecated","affected_versions":"<= 0.6.1 (all versions)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"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.","cause":"The command you are searching for (`my_command`) might be an internal shell command (e.g., `date`, `dir`) on Windows, not a standalone executable file that exists on the system's PATH. `whichcraft.which` primarily finds external executable files.","error":"which('my_command') returns None on Windows when I expect a path, but works on Linux."},{"fix":"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.","cause":"This typically means the `whichcraft` package is either not installed, or there's a typo in the import statement, or there's a naming conflict with another module or file named `whichcraft.py` in your project's directory or Python path.","error":"ImportError: cannot import name 'which' from 'whichcraft' (or similar import errors)"}]}