Convert Python To exe Tutorial

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.

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 –

Convert Python To exe Tutorial
Convert Python To exe Tutorial

 

 Installing cx_Freeze module

For installing cx_Freeze module you have to open terminal. So let’s open terminal and run the following command –

Now cx_Freeze module installed successfully.

Python Program For Converting python file to exe file

Now write the following code in your python file.

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 –
  1. name : It is the name we want our executable to be.
  2. version : It is just a version number.
  3. description : It is all the details we want to give our executable(optional).
  4. 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 –

This will create an exe file.

Convert Python To exe Tutorial
Convert Python To exe Tutorial

Now you can see, a build folder has been created inside your project folder.

Convert Python To exe Tutorial
Convert Python To exe Tutorial

 

Now open the build folder, you will get something like this –

Convert Python To exe Tutorial
Convert Python To exe Tutorial

Now open this folder you will get following result –

Convert Python To exe Tutorial
Convert Python To exe Tutorial

Now you can see your exe file is successfully created.

Related Articles :

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.

 

Leave a Comment