Lazy loaded image
🌓How to Use Pyinstaller to Generate an EXE File
Words 492Read Time 2 min
Jan 10, 2024
Aug 6, 2025

How to Use Pyinstaller to Generate an EXE File

type
status
date
slug
summary
tags
category
icon
As a Data Analyst, one common challenge I face is trying to share a python script for data processing with colleagues who may not have an IT background or are not familiar with Python. Oftentimes, their computers do not have Python environment.
Pyinstaller is an incredibly useful tool for packaging your Python code into a standalone executable file. This makes it simple to distribute and run your code on various systems without the need for users to have Python installed. In this blog post, we'll guide you through the process of using Pyinstaller to create an EXE file from your Python script.

Packaging Python Code with PyInstaller

Step 1: Install pyinstaller

Make sure Pyinstaller is installed on your system using pip. Run the following command in your terminal or command prompt to install it.

Step 2: Navigate to Your Python Script

Navigate to the directory where your Python script is located using the terminal or command prompt.

Step 3: Run Pyinstaller

To generate an EXE file from your Python script, you can use the following command:
In this command, -F specifies that you want a executable file, which includes all third-party dependencies, resources, and code. Replace python_script.py with the name of your Python script.

Step 4: Locate the Generated EXE File

After running the Pyinstaller command, you will find that three folders are generated: pycache, build, and dist. The dist folder contains the executable file of your Python script. You can now distribute this EXE file to others, and they can run your script without needing to install Python!
 

Exploring further more options

There are numerous options available for customization when using pyinstaller. Some commonly used examples include:
  1. -n, --name: Allows you to specify the name of the executable file.
    1. -w, --windowed: Causes the console window to be hidden when the program is run.
      1. -y, -noconfirm: Replace output directory (default: SPECPATH/dist/SPECNAME) without asking for confirmation.
      1. -additional-hooks-dir: Specifies a directory to search for additional hooks.
       

      Packaging Python Code with GUI

      If you find the options for packaging Python scripts to be complex and are seeking a more straightforward solution, Auto-py-to-exe is an excellent tool to consider. It offers a user-friendly graphical interface for converting Python scripts into standalone executable files using Pyinstaller. This tool streamlines the process by guiding users through the necessary configurations and options, making it easier to create executable files from Python scripts.
       
      Here's how you can use it:

      Installation:

      First, ensure that you have auto-py-to-exe installed.

      Usage:

      Once auto-py-to-exe is installed, you can run the tool by executing the following command in your terminal or command prompt:
      This command will open a graphical user interface (GUI) for auto-py-to-exe, allowing you to proceed with the conversion process.
      notion image
       

      Customization:

      The tool offers various customization options, including the ability to set the icon for the executable file and choose whether the console window should be shown during execution. These options are presented within the GUI, making it easy to configure the desired settings for the executable file.
      上一篇
      Saving Dataframes into Oracle Database with Python
      下一篇
      Using Python to Retrieve Data Through Tableau REST-API

      Comments
      Loading...