Photo by Markus Spiske from Pexels
Using Auto PY to EXE we can convert .py
files to .exe
files very easily. This way our Python project will act as a desktop application. And we will be able to run the application on other windows machines without installing Python.
In this article, you will learn how to convert a Python project to an executable file. The process will work whether your application has just one .py
file or a several .py
files. Note that Auto PY to EXE works only in Python version 3.5 or higher. So you can’t use it in Python version lower than 3.5.
Installing Auto PY to EXE
Installing using pip
Installing Auto PY to EXE is a fairly easy process. Using pip we can install it on our computer very easily. Running the following command will install the current version of Auto PY to EXE.
$ pip install auto-py-to-exe
Installing from GitHub
We can also install it directly from GitHub. To install Auto PY to EXE from GitHub first we need to clone the GitHub repository.
$ git clone https://github.com/brentvollebregt/auto-py-to-exe.git
Then we need to navigate to the auto-py-to-exe
directory.
$ cd auto-py-to-exe
Now we need to run the setup.py
file.
$ python setup.py install
We can also check the version by running this command:
$ auto-py-to-exe --version
Checking the version
The current version of Auto PY to EXE is 2.9.0 and it is now installed on our computer.
Opening the Application
To open Auto PY to EXE we have to execute the following command from the terminal:
$ auto-py-to-exe
This will open a nice GUI application that looks like this:
The user interface of Auto PY to EXE
Now we can convert our .py
file to .exe
using this interface.
Steps to Convert
Step 1. Adding the file location
To convert .py
to .exe
first, we need to give the path of the Python file. We just need to browse to the location of the file we want to convert and then add the path.
Look at the example below:
Adding the file location
I added the location of the main Python file of my project. Here I am using one of my Python projects. It is a GUI application that visualizes various sorting algorithms. I wrote an article on how to make this project. You can read it here:
Step 2. Choosing ‘One Directory’ or ‘One File’
Then there will be an option to choose ‘One Directory’ or ‘One File’. My Python project had several other files so I decided to choose the ‘One Directory’ option. It will create a directory with all necessary files along with the .exe
file.
One directory or One file
Step 3. Choosing ‘Console Based’ or ‘Window Based’
After that, there will be an option whether we want our application to be ‘Console Based’ or ‘Window Based’. Choosing ‘Window Based’ will hide all the console outputs of the application. If your project generates console-based outputs then you need to choose ‘Console Based’. But if you have a GUI application or you don’t want to show the console outputs to the users then you need to choose ‘Window Based’. I am choosing the second option because my application is a GUI application.
Console based or Window based
Step 4. Converting
Now we will see some more options like adding icons, additional files, etc. You can choose those options as per your need. But for now, our .py
file is ready to convert. We just need to press the CONVERT .PY TO .EXE button.
Press the button to convert
We need to wait a bit to complete the process.
The Output Folder
After the process is completed we will have an option to open the output folder.
Opening the output folder
By default, the output folder will be created from where we opened Auto PY to EXE. In my case, I opened Auto PY to EXE from the desktop. So the output folder is created in this location. The output folder will have a lot of files and folders. But our concern is the file with .exe
extension. For me it was main.exe
. Double-clicking on this file will open the program.
Done! Our Python project is now converted into an executable file. We can now run the application on other computers without having to install Python.
Conclusion
And that’s it! Now you know an easy solution to convert your Python project to an executable application. This will come in very handy if you want to share your project with others who may not have Python installed on their computer. I hope you find it helpful. Thanks for reading.
Resources
- https://pypi.org/project/auto-py-to-exe/
- https://github.com/brentvollebregt/auto-py-to-exe