Apne Python GUI application ko ek professional executable file mein convert karna zaroori hai taaki aapka source code surakshit rahe aur users bina Python install kiye ise chala sakein. Is article mein hum seekhenge ki Python App ko EXE Banaye kaise, aur phir use OpenSSL se digitally sign kaise karein taaki uski authenticity bani rahe.
Python App ko EXE Banaye: Step-by-Step Guide
Apne Python GUI app ko .exe file mein convert karne ke liye ye steps follow karein. Isse aapka source code secure rahega, bina Python installation ke app chalega, aur CMD window bhi nahi khulegi.
Step 1: PyInstaller Install Karein
Sabse pehle, Command Prompt mein neeche di gayi command run karke pyinstaller library install karein:
PowerShell
pip install pyinstaller
Step 2: .exe File Banane Ka Process
- Apni Python file ko
.pywextension ke saath save karein (e.g.,url_shortener.pyw)..pywextension console window ko suppress karta hai. - Command Prompt mein apne project folder ka path open karein.
- Ek single executable file banane ke liye jo CMD window na khole, yeh command run karein:
PowerShell
pyinstaller --onefile --noconsole url_shortener.pyw
Step 3: Important Flags Explained
--onefile→ Yeh flag sabhi dependencies ko ek hi.exefile mein bundle karta hai.--noconsole→ Yeh flag application ke saath open hone waali Command Prompt (CMD) window ko band kar deta hai.url_shortener.pyw→ Yahan aapki Python file ka naam aayega.
Step 4: Output Location
Process poora hone ke baad, aapki .exe file dist folder ke andar milegi.
Path example: C:\Users\sunny\Desktop\dist\url_shortener.exe
Step 5: Code Protection (Optional but Recommended)
Aap additional security ke liye apne code ko obfuscate ya encrypt bhi kar sakte hain.
--keyflag se encryption karein.- Third-party tools, jaise PyArmor ka use karein.
Command for Code Obfuscation using PyArmor:
PowerShell
pyarmor pack -e " --onefile --noconsole" url_shortener.pyw
OpenSSL Se EXE File Sign Karein (Python App ko EXE Banaye)
Digital signature file ki authenticity aur integrity ko verify karta hai. OpenSSL is a powerful tool that helps generate certificates karke apni .exe file sign kar sakte hain.
Step 1: OpenSSL Install Karein
🔹 Windows Users Ke Liye:
OpenSSL Download Link se ise install karein. Installation ke waqt “Add OpenSSL to System PATH” option ko zaroor enable karein.
Installation verify karne ke liye Command Prompt (CMD) mein yeh command run karein:
Nginx
openssl version
✅ Agar version show ho raha hai toh installation successful hai.
Step 2: Private Key Aur Certificate Generate Karein
Ab hum ek private key, ek Certificate Signing Request (CSR), aur ek self-signed certificate banayenge.
- Private Key Generate Karein: CMD mein yeh command likhein:C#
openssl genrsa -out privatekey.key 2048✅ Yeh 2048-bit ki ek private key (privatekey.key) file banayega. - Certificate Signing Request (CSR) Generate Karein: CMD mein yeh command likhein:VB.Net
openssl req -new -key privatekey.key -out request.csr👉 Aapse kuch details maangi jayengi:- Country Name (2-letter code): IN
- State or Province Name: Uttar Pradesh
- Locality Name (eg, city): Lucknow
- Organization Name (eg, company): WebLeex
- Organizational Unit Name (eg, section): IT Department
- Common Name (eg, YOUR name): webleex.com
- Email Address: support@webleex.com
- Self-Signed Certificate Generate Karein: CMD mein yeh command likhein: C#
openssl x509 -req -days 365 -in request.csr -signkey privatekey.key -out certificate.crt✅ Yeh command 1 saal ke liye valid ek self-signed certificate (certificate.crt) banayega.
Step 3: .pfx File Generate Karein
.pfx (PKCS#12) file mein certificate aur private key dono hote hain. Ise banane ke liye yeh command run karein:
Objective-C
openssl pkcs12 -export -out MyCert.pfx -inkey privatekey.key -in certificate.crt
👉 Aapse .pfx file ke liye ek password set karne ko kaha jayega. Isse yaad rakhein.
✅ MyCert.pfx file ab signing ke liye taiyaar hai.
Step 4: EXE File Ko SignTool Se Sign Karein 🔐
Ab hum signtool (Windows SDK ka hissa) ka use karke apni .exe file sign karenge.
- EXE Sign Karein: CMD mein yeh command likhein: Bash
signtool sign /f "MyCert.pfx" /p "YourPassword" /tr http://timestamp.digicert.com /td SHA256 "YourApp.exe"📌 Replace karein:"MyCert.pfx"→ Aapki generate ki hui.pfxfile ka path."YourPassword"→ Jo password aapne.pfxfile banate waqt set kiya tha."YourApp.exe"→ Aapki actual EXE file ka path.
- Signature Verify Karein: Signature verify karne ke liye yeh command run karein: PowerShell
signtool verify /pa "YourApp.exe"✅ Agar output mein “Successfully verified” show ho, toh aapki file sahi se sign ho chuki hai.
