theroyalnamdeo
Wednesday, 2025-01-22
If you’ve ever developed a Python script and wanted to share it with someone who doesn’t have Python installed on their system, converting your .py file into a standalone executable (.exe) is a great solution. This blog will guide you through the process of converting a .py file into a .exe file using tools like pyinstaller.
.exe file..py to .exePyInstaller is one of the most popular tools for converting Python files to executables. To install it, open a terminal or command prompt and run:
pip install pyinstaller
Navigate to the directory containing your .py file using the cd command. For example:
cd path/to/your/script
Run the following command to create an executable:
pyinstaller --onefile script_name.py
Here:
--onefile: Ensures that all dependencies are bundled into a single .exe file.script_name.py: Replace this with the name of your Python script.Once the process completes, you’ll find your .exe file in the dist folder within your script’s directory. For example:
project-folder/
dist/
script_name.exe
If you want your .exe file to have a custom icon, include the --icon option in your command:
pyinstaller --onefile --icon=icon.ico script_name.py
Replace icon.ico with the path to your .ico file.
.exe file doesn’t run as expected, use the --console flag to see error messages.--exclude-module option to reduce file size by excluding unused modules.pip freeze to ensure you’ve installed everything.UPX to compress files.