def _mac_elevate():
    """Relaunch asking for root privileges."""
print('Relaunching with root permissions')
applescript = 'do shell script "./my_program" with administrator privileges'
exit_code = subprocess.call(['osascript', '-e', applescript])
sys.exit(exit_code)
Get root dialog in Python on Mac OS X, Windows?