Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Command Line Scripts | Python Packaging
Next article icon

Convert Python Script to .exe File

Last Updated : 26 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

We create lots of Python programs per day and want to share them with the world. It is not that you share that Python program with everyone, and they will run this script in some IDLE shell. But you want everyone to run your executable python script without the installation of Python. So for this work, you can convert the .py file to .exe file. In this article, you will learn how you can convert .py file to .exe file. Follow the below steps for the same. 

Tools for Conversion

There are Several tools are available for converting executable Python script. The most popular ones include:

  1. PyInstaller
  2. cx_Freeze
  3. py2exe

In this article, we’ll focus on using PyInstaller due to its ease of use and powerful features.

Steps to Python Scripts to .Exe Files

Step 1: Install PyInstaller

Type below command in the command prompt to create python to executable.  

pip install pyinstaller

Step 2: Navigate to Your Script’s Directory

Go into the directory where your ‘.py’ file is located. 

Convert-.py-to.exe

Step 3: Open PowerShell

Press the shift⇧ button and simultaneously right-click at the same location. You will get the below box. 

Click on ‘Open PowerShell window here’.  You will get a window shown below. 

convert .py to .exe

Step 4: Run PyInstaller

Type the command given below in that PowerShell window. 

The –onefile option ensures that PyInstaller creates a single executable file rather than a directory with multiple files. Here the ‘.py’ file name is ‘1’. 

pyinstaller --onefile -w 'filename.py'

Convert-.py-to.exe

After typing the command ‘Hit the Enter’. It will take some time to finish the process depending on the size of the file and how big is your project. After the processing has been finished, the window will look as below:  

Convert-.py-to.exe

In Case of Error

In case you get an error at this point in the PowerShell window like this:  

convert .py to .exe

The correction while typing the above command:  

.\pyinstaller --onefile -w 'filename.py'

For any missing package:
pyinstaller --hidden-import 'package_name' --onefile 'filename.py' 

Convert-.py-to.exe

After typing the command ‘Hit the Enter’. It will take some time to finish the process depending on the size of the file and how big is your project. After the processing has been finished, the window will look as above:

Step 5: Locate the Executable

See the directory it should look like this: 

Convert-.py-to.exe

‘build’ folder and ‘1.spec’ is of no use. You can delete these if you want, it will not affect your ‘.exe’ file.  

Convert-.py-to.exe

Step 6: Test the Executable

Open ‘dist’ folder above. Here you will get your ‘.exe’ file.  

Convert-.py-to.exe

Right-click on the file and check the properties. 

Convert-.py-to.exe

Additional PyInstaller Options

PyInstaller provides several options to customize the build process:

  • –onefile: Bundles the script and all dependencies into a single executable.
  • –windowed: Suppresses the console window (useful for GUI applications).
  • –icon: Allows you to specify an icon for the executable.

Conclusion

Converting Python scripts to executable files can significantly simplify the distribution and execution of your programs. PyInstaller is a powerful tool that makes this process straightforward, allowing you to create executables that are easy for end-users to run.

By following the steps outlined in this article, you can convert your Python scripts to .exe files efficiently. Explore additional options and configurations provided by PyInstaller to further customize your executable files according to your needs.



Next Article
Command Line Scripts | Python Packaging
author
mkumarchaudhary06
Improve
Article Tags :
  • Python
  • Technical Scripter
  • python-utility
  • Technical Scripter 2019
Practice Tags :
  • python

Similar Reads

  • Convert Excel to PDF Using Python
    Python is a high-level, general-purpose, and very popular programming language. Python programming language (latest Python 3) is being used in web development, Machine Learning applications, along with all cutting-edge technology in Software Industry. In this article, we will learn how to convert an
    2 min read
  • How To Embed Python Code In Batch Script
    Embedding Python code in a batch script can be very helpful for automating tasks that require both shell commands and Python scripting. In this article, we will discuss how to embed Python code within a batch script. What are Batch Scripts and Python Code?Batch scripts are text files containing a se
    4 min read
  • Is Bash Script Better Than Python
    Programming languages let you create programs and various online solutions like web apps, games, mobile apps, etc. There are multiple computer languages online that you can use to automate, assemble, interpret, and manage data processing. Programming languages like Bash and Python are prevalent amon
    6 min read
  • How to Run a Python Script
    Python scripts are Python code files saved with a .py extension. You can run these files on any device if it has Python installed on it. They are very versatile programs and can perform a variety of tasks like data analysis, web development, etc. You might get these Python scripts if you are a begin
    6 min read
  • Command Line Scripts | Python Packaging
    How do we execute any script in Python? $ python do_something.py $ python do_something_with_args.py gfg vibhu Probably that's how you do it. If your answer was that you just click a button on your IDE to execute your Python code, just assume you were asked specifically how you do it on command line.
    4 min read
  • How to setup Notepad to run Python Script
    Due to its simplicity, versatility, and readability, Python has become phenomenally popular as a computer language that is highly leveled and dynamically typed. These are some of the IDEs for Python development that have many tools; however, if you are just starting or want it lighter, then Windows’
    2 min read
  • Schedule a Python Script to Run Daily
    In this article, we are going to see how to schedule a Python Script to run daily. Scheduling a Python Script to run daily basically means that your Python Script should be executed automatically daily at a time you specify. Step-by-Step ImplementationCreate a Python file, for example: gmail_automat
    3 min read
  • Python Script to Automate Software Installation
    Software installation can often be a time-consuming and monotonous undertaking, particularly when dealing with multiple applications. Python scripting gives a solution by enabling automation of the entire installation process which leads to more time consuming, enhances productivity, and gets rid of
    4 min read
  • Convert Docx to Pdf using docx2pdf Module in Python
    Tired of having to use online docx to PDF converters with crappy interfaces and conversion limits? Then, look no further than your friendly neighborhood language python's docx2pdf module. This module is a hidden gem among the many modules for the python language. This module can be used to convert f
    2 min read
  • How to Make Script Executable in Linux | chmod Command
    In Unix operating systems, the chmod command is used to change the access mode of a file. The name is an abbreviation of change mode. Which states that every file and directory has a set of permissions that control the permissions like who can read, write or execute the file. In this the permissions
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences