```python import shutil which_wakeonlan = shutil.which("wakeonlan") ``` # Also ```py # simple path search import os path = os.getenv("PATH") ps = path.split(":") n = "bobbins" for x in ps: if os.path.isfile(os.path.join(x,n)) and os.access(os.path.join(x,n), os.X_OK): print(os.path.join(x,n)) break # is executable in path # from https://stackoverflow.com/questions/377017/test-if-executable-exists-in-python my_command = 'ls' x = any( ( os.access(os.path.join(path, my_command), os.X_OK) and os.path.isfile(os.path.join(path, my_command)) ) for path in os.environ["PATH"].split(os.pathsep) ) if x: print("found",my_command) import shutil print(shutil.which("ls")) ``` Note `any(xs)` returns `True` if any element of the iterable `xs` is `True`, else `False`.