Mac OS Catalina 10.15
I am developing a software in python. I would like to distribute it as commercial software.
I am compiling it with Nuitka for Windows and PyInstaller for Mac (because Nuitka can’t do the job on Mac).
My software need to install some libraries and other stuff like JDK, SDK tools, etc…
It needs also to change some environment variables. This can be done only with admin permissions.
So the first thing my software does is to check if it is running with admin permissions or not. If it is not the case it restart itself with admin permissions.
I succeeded to do it for Windows, but I have issues for Mac.
Here is the code:
def is_admin(): try: is_admin = os.getuid() == 0 except AttributeError: is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0 return is_admin def StartMyAppasAdmin(): if not is_admin(): if platform.system() == 'Windows': ctypes.windll.shell32.ShellExecuteW(None, "runas", 'hello.exe', '', None, 1) sys.exit() elif platform.system() == 'Darwin': subprocess.call(["sudo","/usr/bin/open", os.path.join(os.path.dirname(sys.argv),"hello")]) sys.exit() if __name__ == "__main__": StartMyAppasAdmin()
In Windows, it works fine.
In Mac OS, the app can’t be launch. And if I open the executable from terminal, it ask for admin password, then it restart and ask again for admin password, then it restart, etc… in a loop.
Someone knows what I am doing wrong?