Hi everyone, if you are trying to convert python file into exe file, then you came at the right place. In this post we will learn how to convert python file into exe file. So let’s start Convert Python To exe tutorial.
Contents
Convert Python To exe Tutorial
So we have many tools to convert python files into exe files. These tools are third party modules that should be installed by yourself because it don’t came along with python itself.
Some modules using which you can convert python file into exe file are following –
All these are easy to use but in this tutorial i will use cx_Freeze.
The reason for using cx_Freeze and not Py2exe or Pyinstaller is that because Py2exe and Pyinstaller are not working with python(latest version) 3.5 and 3.6. If you are using python 3.4 or below versions then no issue, you can use Py2exe or Pyinstaller.
So now let’s move ahead.
Creating New Project
So now as usual create a project on your IDE(i am using PyCharm) and create a python file inside this. so my project is like that –
Installing cx_Freeze module
For installing cx_Freeze module you have to open terminal. So let’s open terminal and run the following command –
1 2 3 |
pip install cx_Freeze |
Now cx_Freeze module installed successfully.
Python Program For Converting python file to exe file
Now write the following code in your python file.
1 2 3 4 5 6 7 8 9 |
from cx_Freeze import setup,Executable setup(name = "Pandas", version ="1.0", description = " Pandas example", executables = [Executable(r"C:\Users\saba\PycharmProject\Python_Pandas\Python_Pandas_Example.py")] ) |
What We Did ?
- First of all we have imported setup and Executable from cx_Freeze.
- Then we have called the setup function. It has four parameters which are as follows –
- name : It is the name we want our executable to be.
- version : It is just a version number.
- description : It is all the details we want to give our executable(optional).
- executables : This is the most important part. In this you have to write Executable inside the square bracket and inside the parenthesis of Executable you have to pass the path of that file which you want to convert into exe.
(Here i have describe the full path because my file resides in another directory but if your file resides in same directory then you don’t need to pass full path)
Running The Above Python Code
Now go to your terminal and run the following code –
1 2 3 |
python python-to-exe.py build |
This will create an exe file.
Now you can see, a build folder has been created inside your project folder.
Now open the build folder, you will get something like this –
Now open this folder you will get following result –
Now you can see your exe file is successfully created.
Related Articles :
- Merge Sort Python Tutorial – An Efficient Way Of Sorting
- Selection Sort Python – A Quick Tutorial and Implementation Guide
- HTML to PDF Django Tutorial – Converting HTML to PDF
- Python Binary To Decimal Tutorial With Examples
So guys that is all about Convert Python To exe Tutorial. I hope you have enjoyed it and if you have any query regarding this then feel free to comment. And please share this post with your friends for helping me.