If you write a Python program that solves a problem, then you need to manually run the code every time you want to use it. It could be easy for you since you are a programmer. But if you want to give that program to someone who doesn’t know coding, it could be a big challenge for them to run it through the command line or any IDE.
That’s why it would be great if you can make that Python script into an EXE app (.exe file) so that the user can just click a button, and boom!, the app is running. In this post, let’s learn how to convert your python scripts into .exe files within a few simple steps.
Install the Pyinstaller module
We will be using the pyinstaller module in Python to create EXE applications from Python files. If you haven’t installed pyinstaller yet, you can open your command prompt and type in the following command.
pip install pyinstaller
Once it is installed, let’s do the following steps.
I hope you have a Python file that you want to convert. Navigate to the folder where your Python file is located using the “cd” command on the command prompt.
where Folder_Path is the path of the folder in which your Python file is located.
Now, let’s run the following command to convert your Python file to an EXE application.
pyinstaller -F -w file_name.py
where file_name.py is the file name of your Python file.
Once you enter the above command on your command prompt, pyinstaller will work its magic and your EXE app will be automatically created. You will see that some new folders will be created and you will have an executable file inside the “dist” folder.
Adding an icon to your EXE app
If you want to add an icon to your EXE app to make it look cool, you can do that easily with pyinstaller. You just need a “.ico” file. You can search online and find an icon (.ico file) for your app. Download the icon and put it inside the folder where your python file is located.
Now, you can run the following command to create an EXE application that has a cool icon.
pyinstaller -F -w -i icon_name.ico file_name.py
where icon_name.ico is the name of your icon file and file_name.py is the name of your Python file.
You can find your EXE app inside the “dist” folder, which was automatically created when you run the above command. This .exe file is an executable file that you can run on any Windows computer by double-clicking on the file.
Now you know how to create a “real” desktop application using Python. You can share this app even with people who don’t know programming. They can just run it conveniently on their computers.
If you don’t want to do it using pyinstaller, you can also use a software called py2exe. You can download this software and convert your Python files into .exe files.
I hope this post was helpful. Happy coding!