We create lots of Python programs per day and want to share it 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 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.
Install the library
Type below command in the command prompt.
pip install pyinstaller
Go into the directory where your ‘.py’ file is located.
Press shift⇧ button and simultaneously right click at the same location. You will get below box.
Click on ‘Open PowerShell window here’.
You will get a window shown below.
Type the command given below in that PowerShell window.
pyinstaller --onefile -w 'filename.py'
My ‘.py’ file name is ‘1’.
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'
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:
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.
Open ‘dist’ folder above. Here you will get your ‘.exe’ file.
Right-click on the file and check the properties.
- Convert Text file to JSON in Python
- Convert Text and Text File to PDF using Python
- Python program to reverse the content of a file and store it in another file
- How to convert an array to CSV file in PHP ?
- reStructuredText | .rst file to HTML file using Python for Documentations
- How to Run a Python Script
- Convert byte array to File using Java
- Run python script from anywhere in linux
- Python Script to Shutdown Computer
- Get directory of current Python script
- Python Script to Restart Computer
- Python Script to Logout Computer
- Python | Accepting Script Input
- Schedule a Python Script on PythonAnywhere
- Autorun a Python script on windows startup
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.