How do I make an executable from a Python script?


To make an executable from a Python script, you need to install the PyInstaller library.

Install the PyInstaller Library

To install the PyInstaller library, use the pip in Python. Type the below command on Command Prompt and press Enter −

pip install pyinstaller

Our Python Script

Let’s say we have the following Python Script, wherein we have displayed checkbox using Tkinter. Our file Demo.py is saved on the Desktop with the path −

C:\Users\hp\Desktop\Demo.py

Example

Here’s the code of Demo.py.

import tkinter from tkinter import * top = tkinter.Tk() CheckVar1 = IntVar() CheckVar2 = IntVar() C1 = Checkbutton(top, text = "Cricket", variable = CheckVar1, \ onvalue = 1, offvalue = 0, height=5, \ width = 20) C2 = Checkbutton(top, text = "Football", variable = CheckVar2, \ onvalue = 1, offvalue = 0, height=5, \ width = 20) C1.pack() C2.pack() top.mainloop()

Output


Create an Executable

Now, we will use the PyInstaller library to create an executable of our Python script Demo.py.

Open cmd and reach the location wherein the script is located −


Now, type the following command with the name of the script file Demo.py −


The above will create an executable, which will be the executable from the Demo.py file.

Updated on: 20-Sep-2022

815 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements