Python subprocess on Windows, Mac and Linux

Paths to executables for Python subprocess on Windows and other operating systems are handled cleanly as follows.

A simple boilerplate method to handle these issues follows, typically put in __init__.py for your package or other suitable location

#!/usr/bin/env python
from pathlib import Path
import os

# directory of this Python .py file
R = path(__file__).resolve().parent
# wherever your executable is
EXE = R / '..' / 'build' / 'myprogram'

if os.name == 'nt':
    EXE = EXE.with_suffix('.exe')

if not EXE.is_file():
	raise FileNotFoundError(EXE)


def myfunc():

	# cast EXE to str() in general with subprocess
    cmd = [str(EXE), myparam1, myparam2]

    subprocess.check_call(cmd)