close

How To Create Exe File from Python Script

Hello Guys. How Are You All ? Hope You All Are Fine. Sometimes We need to create Our Python Script to Executable File. So In this tutorial We are Going to learn How To Create Exe File from Python Script in very Easy Step. So without wasting Your Time lets start this tutorial step by step.

How To Create Exe File from Python Script?

  1. How To Create Exe File from Python Script

    To Create Exe File from Python Script Just Follow All Below Step To Create Executable from Python Script using Pyinstaller. Install Pyinstaller Package.Save Your Python Script.Create the Executable File using Pyinstaller.Run Your Executable File.

  2. Create Exe File from Python Script

    To Create Exe File from Python Script Open Your Command Prompt and Just Run Below Command To Install Pyinstaller Package: pip install pyinstaller Now, You need to make Your Python Script And Save Your Python Script. Here I have just created simple python script. Now, Just Run this Pyinstaller Command To Create Executable File: pyinstaller –onefile pythonScriptName.py Now You can See dist folder there. Just Open dist Folder and Run Exe file.

  3. Create Executable from Python Script using Pyinstaller

    To Create Exe File from Python Script Open Your Command Prompt and Just Run Below Command To Install Pyinstaller Package: pip install pyinstaller Now, You need to make Your Python Script And Save Your Python Script. Here I have just created simple python script. Now, Just Run this Pyinstaller Command To Create Executable File: pyinstaller –onefile pythonScriptName.py Now You can See dist folder there. Just Open dist Folder and Run Exe file.

Just Follow All Below Step To Create Executable from Python Script using Pyinstaller.

  1. Add Python To Your PATH Variable.
  2. Install Pyinstaller Package.
  3. Save Your Python Script.
  4. Create the Executable File using Pyinstaller.
  5. Run Your Executable File.

1. Add Python To Your PATH Variable.

First Of All You Need To add Your Python Path To Your Environment Variable Just Follow This Article.

  1. First of all click start Button
  2. Then Search Environment Variable
  3. Then Select Environment Variables.. at the bottom
  4. Now in System variables Search PATH and Edit it
  5. Then Click on New button and Paste your Python installation Path There.
  6. You have to add python install directory, bin, and lib-scripts in path.

If Your Python PATH already Added into your Environment Variable Then You Can Skip This Step.

2. Install Pyinstaller Package.

Open Your Command Prompt and Just Run Below Command To Install Pyinstaller Package.

pip install pyinstaller

3. Save Your Python Script.

Now, You need to make Your Python Script And Save Your Python Script. Here I have just created simple python script.

import tkinter as tk

root= tk.Tk()

canvas1 = tk.Canvas(root, width = 500, height = 500)
canvas1.pack()

def hello ():  
    label1 = tk.Label(root, text= 'Hello World!', fg='red')
    canvas1.create_window(250, 400, window=label1)
    
button1 = tk.Button(text='Click Here',command=hello, bg='brown',fg='white')
canvas1.create_window(250, 250, window=button1)

root.mainloop()

And I have Saved This Code into Python_to_exe.py File In My Python To Exe File Folder.

4. Create the Executable File using Pyinstaller.

Now, We can Make Our Executable File Using This command. All You Need is just Open Your Folder where You have Python Script And Open Terminal From That Folder Where You have Python Script.

In My case My Python_to_exe.py File Is In My Python To Exe File Folder. So I have Opened My Terminal From Python To Exe File Folder Just Like Below.

Now, Just Run this Pyinstaller Command To Create Executable File.

pyinstaller --onefile pythonScriptName.py

In my case my file name is Python_to_exe.py So my Command Is Just like below.

pyinstaller --onefile Python_to_exe.py

Here Is My Output.

Microsoft Windows [Version 10.0.19044.1466]
(c) Microsoft Corporation. All rights reserved.

F:\Python To Exe File>pyinstaller --onefile Python_to_exe.py
210 INFO: PyInstaller: 4.8
210 INFO: Python: 3.7.8

.
.
.
.
14977 INFO: Appending PKG archive to EXE
18273 INFO: Building EXE from EXE-00.toc completed successfully..

And In Your Python To Exe File Folder You Will Se Just Like Below All Files.

5. Run Your Executable File

Now You can See dist folder there.

Just Open dist folder and there You can see Your same as your Python File name Executable File.

Just Run This File. In my example, once you click on the Python_to_exe.exe executable File, you’ll see the following display with a single Click Here button.

And If you click on this button, you’ll see the expression of Hello World!

Conclusion

It’s all About this Tutorial. Hopefully Now You are able To make Your Python Script To Exe File. Comment Below your feedback. Thank You!

Also, Read

Leave a Comment