Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] Python to .exe – How to Make a Python Script Executable?

#1
Python to .exe – How to Make a Python Script Executable?

5/5 – (1 vote)

I have a confession to make. I use Windows for coding Python.


This means that I often need to run my practical coding projects as Windows .exe files, especially if I work with non-technical clients that don’t know how to run a Python file.

In this tutorial, I’ll share my learnings on making a Python file executable and converting them to an .exe so that they can be run by double-click.

PyInstaller



To make a Python script executable as a .exe file on Windows, use a tool like pyinstaller. PyInstaller runs on Windows 8 and newer.

⭐ Pyinstaller is a popular package that bundles a Python application and its dependencies into a single package, including an .exe file that can be run on Windows without requiring a Python installation.

Here are the general steps to create an executable file from your Python script using Pyinstaller:

  1. Install Pyinstaller by opening a command prompt and running the command: pip install pyinstaller or pip3 install pyinstaller depending on your Python version.
  2. Navigate to the directory where your Python script is located in the command prompt using cd (command line) or ls (PowerShell).
  3. Run the command: pyinstaller --onefile your_script_name.py. This command creates a single executable file of your Python script with all its dependencies included.
  4. After the command completes, you can find the executable file in a subdirectory called dist.
  5. You can now distribute the executable file to users, who can run it on their Windows machines by double-clicking the .exe file.

What Does the –onefile Option Mean?


The --onefile file specifier is an option for Pyinstaller that tells it to package your Python script and all its dependencies into a single executable file.

By default, Pyinstaller will create a directory called dist that contains your script and a set of related files that it needs to run. However, using the --onefile option, Pyinstaller will generate a single .exe file, which is more convenient for the distribution and deployment of the application.

1-Paragraph Summary


To convert a Python file my_script.py to an executable my_script.exe using Pyinstaller, install Pyinstaller using pip install pyinstaller, navigate to the script directory in the command prompt, run pyinstaller --onefile my_script.py, then locate the executable file in the dist folder.

If you want to keep improving your coding skills, check out our free Python cheat sheets!



https://www.sickgaming.net/blog/2023/03/...xecutable/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tut] 5 Expert-Approved Ways to Remove Unicode Characters from a Python Dict xSicKxBot 0 13 10 hours ago
Last Post: xSicKxBot
  [Tut] Python BS4 – How to Scrape Absolute URL Instead of Relative Path xSicKxBot 0 30 12-02-2025, 10:14 AM
Last Post: xSicKxBot
  [Tut] Python Int to String with Trailing Zeros xSicKxBot 0 36 12-01-2025, 05:47 PM
Last Post: xSicKxBot
  [Tut] How to Install xlrd in Python? xSicKxBot 0 42 12-01-2025, 01:23 AM
Last Post: xSicKxBot
  Python Modules for GUI interfaces SickProdigy 0 5,180 02-18-2024, 10:49 AM
Last Post: SickProdigy
  [Tut] How to Convert MIDI to MP3 in Python – A Quick Overview xSicKxBot 0 2,395 09-02-2023, 02:04 PM
Last Post: xSicKxBot
  [Tut] Wrap and Truncate a String with Textwrap in Python xSicKxBot 0 2,054 09-01-2023, 07:45 PM
Last Post: xSicKxBot
  [Tut] Use enumerate() and zip() Together in Python xSicKxBot 0 1,804 08-28-2023, 09:35 AM
Last Post: xSicKxBot
  [Tut] Boolean Operators in Python (and, or, not): Mastering Logical Expressions xSicKxBot 0 1,814 08-27-2023, 02:04 PM
Last Post: xSicKxBot
  [Tut] Python zip(): Get Elements from Multiple Lists xSicKxBot 0 1,973 08-26-2023, 01:28 AM
Last Post: xSicKxBot

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016