03-13-2023, 01:31 AM
Python to .exe – How to Make a Python Script Executable?
5/5 – (1 vote)
I have a confession to make. I use Windows for coding Python.
![[Image: image.gif]](https://blog.finxter.com/wp-content/uploads/2023/03/image.gif)
This means that I often need to run my practical coding projects as Windows files, especially if I work with non-technical clients that don’t know how to run a Python file.
In this tutorial, I’ll share my learnings on making a Python file executable and converting them to an so that they can be run by double-click.
PyInstaller
![[Image: image-140.png]](https://blog.finxter.com/wp-content/uploads/2023/03/image-140.png)
To make a Python script executable as a file on Windows, use a tool like . PyInstaller runs on Windows 8 and newer.
Pyinstaller is a popular package that bundles a Python application and its dependencies into a single package, including an file that can be run on Windows without requiring a Python installation.
Here are the general steps to create an executable file from your Python script using Pyinstaller:
What Does the –onefile Option Mean?
The file specifier is an option for Pyinstaller that tells it to package your Python script and all its dependencies into a single executable file.
By default, Pyinstaller will create a directory called that contains your script and a set of related files that it needs to run. However, using the option, Pyinstaller will generate a single file, which is more convenient for the distribution and deployment of the application.
1-Paragraph Summary
To convert a Python file to an executable using Pyinstaller, install Pyinstaller using , navigate to the script directory in the command prompt, run , then locate the executable file in the folder.
If you want to keep improving your coding skills, check out our free Python cheat sheets!
5/5 – (1 vote)
I have a confession to make. I use Windows for coding Python.
![[Image: image.gif]](https://blog.finxter.com/wp-content/uploads/2023/03/image.gif)
This means that I often need to run my practical coding projects as Windows
Code:
.exeIn this tutorial, I’ll share my learnings on making a Python file executable and converting them to an
Code:
.exePyInstaller
![[Image: image-140.png]](https://blog.finxter.com/wp-content/uploads/2023/03/image-140.png)
To make a Python script executable as a
Code:
.exeCode:
pyinstaller
Pyinstaller is a popular package that bundles a Python application and its dependencies into a single package, including an Code:
.exeHere are the general steps to create an executable file from your Python script using Pyinstaller:
- Install Pyinstaller by opening a command prompt and running the command: orCode:
pip install pyinstallerdepending on your Python version.Code:pip3 install pyinstaller
- Navigate to the directory where your Python script is located in the command prompt using (command line) orCode:
cd(PowerShell).Code:ls
- Run the command: . This command creates a single executable file of your Python script with all its dependencies included.Code:
pyinstaller --onefile your_script_name.py
- After the command completes, you can find the executable file in a subdirectory called .Code:
dist
- You can now distribute the executable file to users, who can run it on their Windows machines by double-clicking the file.Code:
.exe
What Does the –onefile Option Mean?
The
Code:
--onefileBy default, Pyinstaller will create a directory called
Code:
distCode:
--onefileCode:
.exe1-Paragraph Summary
To convert a Python file
Code:
my_script.pyCode:
my_script.exeCode:
pip install pyinstallerCode:
pyinstaller --onefile my_script.pyCode:
distIf you want to keep improving your coding skills, check out our free Python cheat sheets!

