How to request UAC Elevation within Python?

  admin, python, python-3.9, python-3.x, windows

My Python script requires administrator privileges, however I cannot seem to get it working. I want it to be able to request admin privileges but also work when the file is compiled by pyinstaller too.

I tried this:

ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)

But it doesn’t seem to work, it requests admin but does nothing with it.
I am using python version 3.9.9 if that helps.

Source: Windows Questions