Create and Sign an EXE with Python

·

1 min read

The contents of this post are no longer useful.

If you want to turn your python procedure into a signed executable in Windows, just follow the steps below. Note that the strings with captial letters should be changed according to your taste.

Requirements

Procedure

  1. install pyinstaller
    pip install pyinstaller
    
  2. create an .exe from a .py
    pyinstaller /PATH/TO/FILE_TO_COMPILE.py --onefile --noconsole
    
  3. create a personal certificate New-SelfSignedCertificate in PowerShell
    New-SelfSignedCertificate -DNSName "YOURDOMAIN.COM" -CertStoreLocation Cert:\CurrentUser\My -Type CodeSigningCert -Subject “MY PERSONAL CERTIFICATE”
    
  4. sign the .exe with signtool or other GUI supporting tools
    signtool sign /a "/PATH/TO/FILE_TO_SIGN.exe"
    

Additional remarks

  • In the step #2, --onefile allows pyinstaller to generate only one file, which is an .exe, rather than any others, and --noconsole blocks the console window while executing the .exe.