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 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 == '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]