Convert Python Script to .exe File
Last Updated : 26 Jul, 2024
We create lots of Python programs per day and want to share them with the world. It is not that you share that Python program with everyone, and they will run this script in some IDLE shell. But you want everyone to run your executable python script without the installation of Python. So for this work, you can convert the .py file to .exe file. In this article, you will learn how you can convert .py file to .exe file. Follow the below steps for the same.
Tools for Conversion
There are Several tools are available for converting executable Python script. The most popular ones include:
- PyInstaller
- cx_Freeze
- py2exe
In this article, we’ll focus on using PyInstaller due to its ease of use and powerful features.
Steps to Python Scripts to .Exe Files
Step 1: Install PyInstaller
Type below command in the command prompt to create python to executable.
pip install pyinstaller
Step 2: Navigate to Your Script’s Directory
Go into the directory where your ‘.py’ file is located.

Step 3: Open PowerShell
Press the shift⇧ button and simultaneously right-click at the same location. You will get the below box.

Click on ‘Open PowerShell window here’. You will get a window shown below.

Step 4: Run PyInstaller
Type the command given below in that PowerShell window.
The –onefile option ensures that PyInstaller creates a single executable file rather than a directory with multiple files. Here the ‘.py’ file name is ‘1’.
pyinstaller --onefile -w 'filename.py'

After typing the command ‘Hit the Enter’. It will take some time to finish the process depending on the size of the file and how big is your project. After the processing has been finished, the window will look as below:

In Case of Error
In case you get an error at this point in the PowerShell window like this:

The correction while typing the above command:
.\pyinstaller --onefile -w 'filename.py'
For any missing package:
pyinstaller --hidden-import 'package_name' --onefile 'filename.py'

After typing the command ‘Hit the Enter’. It will take some time to finish the process depending on the size of the file and how big is your project. After the processing has been finished, the window will look as above:
Step 5: Locate the Executable
See the directory it should look like this:

‘build’ folder and ‘1.spec’ is of no use. You can delete these if you want, it will not affect your ‘.exe’ file.

Step 6: Test the Executable
Open ‘dist’ folder above. Here you will get your ‘.exe’ file.

Right-click on the file and check the properties.

Additional PyInstaller Options
PyInstaller provides several options to customize the build process:
- –onefile: Bundles the script and all dependencies into a single executable.
- –windowed: Suppresses the console window (useful for GUI applications).
- –icon: Allows you to specify an icon for the executable.
Conclusion
Converting Python scripts to executable files can significantly simplify the distribution and execution of your programs. PyInstaller is a powerful tool that makes this process straightforward, allowing you to create executables that are easy for end-users to run.
By following the steps outlined in this article, you can convert your Python scripts to .exe files efficiently. Explore additional options and configurations provided by PyInstaller to further customize your executable files according to your needs.
Similar Reads
Convert Excel to PDF Using Python
Python is a high-level, general-purpose, and very popular programming language. Python programming language (latest Python 3) is being used in web development, Machine Learning applications, along with all cutting-edge technology in Software Industry. In this article, we will learn how to convert an
2 min read
How To Embed Python Code In Batch Script
Embedding Python code in a batch script can be very helpful for automating tasks that require both shell commands and Python scripting. In this article, we will discuss how to embed Python code within a batch script. What are Batch Scripts and Python Code?Batch scripts are text files containing a se
4 min read
Is Bash Script Better Than Python
Programming languages let you create programs and various online solutions like web apps, games, mobile apps, etc. There are multiple computer languages online that you can use to automate, assemble, interpret, and manage data processing. Programming languages like Bash and Python are prevalent amon
6 min read
How to Run a Python Script
Python scripts are Python code files saved with a .py extension. You can run these files on any device if it has Python installed on it. They are very versatile programs and can perform a variety of tasks like data analysis, web development, etc. You might get these Python scripts if you are a begin
6 min read
Command Line Scripts | Python Packaging
How do we execute any script in Python? $ python do_something.py $ python do_something_with_args.py gfg vibhu Probably that's how you do it. If your answer was that you just click a button on your IDE to execute your Python code, just assume you were asked specifically how you do it on command line.
4 min read
How to setup Notepad to run Python Script
Due to its simplicity, versatility, and readability, Python has become phenomenally popular as a computer language that is highly leveled and dynamically typed. These are some of the IDEs for Python development that have many tools; however, if you are just starting or want it lighter, then Windowsâ
2 min read
Schedule a Python Script to Run Daily
In this article, we are going to see how to schedule a Python Script to run daily. Scheduling a Python Script to run daily basically means that your Python Script should be executed automatically daily at a time you specify. Step-by-Step ImplementationCreate a Python file, for example: gmail_automat
3 min read
Python Script to Automate Software Installation
Software installation can often be a time-consuming and monotonous undertaking, particularly when dealing with multiple applications. Python scripting gives a solution by enabling automation of the entire installation process which leads to more time consuming, enhances productivity, and gets rid of
4 min read
Convert Docx to Pdf using docx2pdf Module in Python
Tired of having to use online docx to PDF converters with crappy interfaces and conversion limits? Then, look no further than your friendly neighborhood language python's docx2pdf module. This module is a hidden gem among the many modules for the python language. This module can be used to convert f
2 min read
How to Make Script Executable in Linux | chmod Command
In Unix operating systems, the chmod command is used to change the access mode of a file. The name is an abbreviation of change mode. Which states that every file and directory has a set of permissions that control the permissions like who can read, write or execute the file. In this the permissions
7 min read