Reputation: 387
Hello everybody.
I have a small python project and want to make it to single executable file. I am using...
My PyInstaller command is,
PyInstaller -y -w -F -n output_file_name --uac-admin --clean source_file.py
this command works properly. But single output file does not ask for admin rights when executed. And there's no shield mark on executable file icon.
When remove the -F option (equivalent to --onefile), output executable file has shield mark on its icon and ask me admin rights. But this is not what I want. I want a single executable file.
I found a manifest file (output_file_name.exe.manifest) in dist\output_file_name folder. So I did...
PyInstaller -y -w -F -n output_file_name --manifest output_file_name.exe.manifest --uac-admin --clean source_file.py
But this command doesn't work. Its single executable file still does not ask for admin rights.
I have removed PyInstaller and installed recent development version.
pip install git+https://github.com/pyinstaller/pyinstaller.git@develop
But the result is same. Its output doesn't have a shield mark on icon and does not ask admin rights.
Do you have any idea?
Please help me!
Upvotes: 4
Views: 6656
Reputation: 839
If you want more direct control over when the program asks for admin privileges, or if you don't want to rely on PyInstaller, you can use the PyUAC module (for Windows). Install it using:
pip install pyuac
pip install pypiwin32
Direct usage of the package is:
import pyuac
def main():
print("Do stuff here that requires being run as an admin.")
# The window will disappear as soon as the program exits!
input("Press enter to close the window. >")
if __name__ == "__main__":
if not pyuac.isUserAdmin():
print("Re-launching as admin!")
pyuac.runAsAdmin()
else:
main() # Already an admin here.
Or, if you wish to use the decorator:
from pyuac import main_requires_admin
@main_requires_admin
def main():
print("Do stuff here that requires being run as an admin.")
# The window will disappear as soon as the program exits!
input("Press enter to close the window. >")
if __name__ == "__main__":
main()
You can then use your PyInstaller command without the UAC option.
(from this answer)
Upvotes: 0
Reputation: 16767
Adding -r prog.exe.manifest,1
to pyinstaller
command line worked for me, after that no need for putting manifest file near exe, pure single exe file.
Upvotes: 0
Reputation: 903
Adding up passion053's answer, in my case I used -F
instead of --onefile
and it works fine for me but yeah you need to add manifest
file in the same directory as your single executable.
Note: I used pyinstaller
version 3.5
. and it works fine for my
Happy Coding!
Upvotes: 0
Reputation: 387
I found what's wrong!
The key point is...
Thank you.
Upvotes: 3