


The Easiest Way to Package Your Python Files(Turn to .exe Files)
1. Introduction
Python is an interpreted language, so it does not produce executable files (e.g., .exe) during compilation. However, many programs are based on Python. To simplify the packaging process, I wrote a program to automate it (with one prerequisite step). This ensures the simplest packaging process you've ever seen. GitHub Repository. If you can, please give it a star. Thank you!
This automated packaging tool is based on the pyinstaller Python library.
The packaging tool relies on conda for creating and managing virtual environments, so the prerequisite step is installing conda (skip this step if you already have it installed).
This program only supports packaging in Windows environments, specifically for creating .exe files.
2. Prerequisite Steps
Step 1: Download from the Official Website
Go to the Anaconda official website and download anaconda. Enter your email and click Submit.
Step 2: Choose Anaconda or Miniconda
Click Download, and Anaconda will select the appropriate platform version for you.
If you want to use conda to manage dependencies, downloading Anaconda is a great choice (it even includes a graphical interface for dependency management). If you're just downloading conda to package Python files, scroll down on the page to find the "Miniconda installer" – this is a better lightweight choice (but lacks a graphical interface).
Step 3: Confirm Installation
Open the downloaded installer and use the default settings. You can change the installation path if you want. After installation, check the Windows Start Menu for Anaconda Prompt or Anaconda Powershell Prompt. If they're present, the installation is successful.
3. Using the Automated Packaging Tool
Step 1: Choose a Tool
The GitHub Repository provides two tools: EasyPackager and PeasyPackager. If you don’t need to add icons (.ico) or package multiple Python files into a single executable, use EasyPackager. Here, we explain how to use EasyPackager.
Note: If conda is installed on the C drive (default installation), remember to run the program as an administrator to avoid permission issues.
Step 2: Use the Base Environment or Create a New Environment
Open EasyPackager_GUI.exe (GUI version recommended). The first option lets you choose between the base environment or creating a new environment.
When using the base environment, the generated executable file tends to be large because Pyinstaller packages all libraries and modules in the environment, even unused ones. This not only makes the executable bulky but also slows its execution. Therefore, it’s highly recommended to use the second method – creating a new environment. Choose new.
Step 3: Select the File to Package
Click "Select file" and choose the Python file to package.
Step 4: Enter Python Version and Dependencies
If using the base environment, skip this step. If you selected new, fill in the following fields:
- Enter the Python version: Specify the Python version required for your program (e.g., 3.10).
- Enter the dependencies' package names: List the required dependency packages (not module names), separated by spaces. For example, if your program uses cv2 and numpy, enter:
opencv-python numpy
Leave this blank if no additional dependencies are needed.
Step 5: Choose Radio Button Options
- Generates a single executable file: Select this to generate a standalone .exe file. If unchecked, additional .dll files will be created alongside the .exe. Strongly recommended to select this.
- Runs the program while opening a command line window: Select this if your program lacks a GUI but includes interactive parts (e.g., input()).
This is an example. The black window is command line, the white one is GUI.
If unsure, select both options.
Step 6: Execute
Click the "Execute" button. A command line window will open. Ensure the window stays on top (do not use your computer for other tasks during execution). When the command line shows “Finish packaging, you can exit right now!”, you can close it.
Step 7: Locate the .exe File
After execution, navigate to the Python file's directory. A dist folder will contain the executable file. Other generated files can be deleted.
If you didn’t select "Generates a single executable file," the folder will include the .exe file and a folder with dynamic link files.
4. About PeasyPackager
PeasyPackager is an advanced version of EasyPackager. It supports adding icons (.ico) to the program and packaging multiple Python files into a single executable.
PeasyPackager is similar to EasyPackager, with a few additional features:
1. Add Program Icon
The “Add icon for the program” option allows users to add an icon to the packaged program. It only supports .ico files. Select this option and click "Select file" to choose the icon file.
2. Package Multiple Python Files
The “Package multiple Python files” option allows users to package multiple .py files. Simply select their paths.
The above is the detailed content of The Easiest Way to Package Your Python Files(Turn to .exe Files). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Fastapi ...

Using python in Linux terminal...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

About Pythonasyncio...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...

Loading pickle file in Python 3.6 environment error: ModuleNotFoundError:Nomodulenamed...

Discussion on the reasons why pipeline files cannot be written when using Scapy crawlers When learning and using Scapy crawlers for persistent data storage, you may encounter pipeline files...
