search
HomeBackend DevelopmentPython TutorialThe 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.

The Easiest Way to Package Your Python Files(Turn to .exe Files)

Step 2: Choose Anaconda or Miniconda

Click Download, and Anaconda will select the appropriate platform version for you.

The Easiest Way to Package Your Python Files(Turn to .exe Files)

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.

The Easiest Way to Package Your Python Files(Turn to .exe Files)

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.

The Easiest Way to Package Your Python Files(Turn to .exe Files)

Step 3: Select the File to Package

Click "Select file" and choose the Python file to package.

The Easiest Way to Package Your Python Files(Turn to .exe Files)

Step 4: Enter Python Version and Dependencies

If using the base environment, skip this step. If you selected new, fill in the following fields:

The Easiest Way to Package Your Python Files(Turn to .exe Files)

  1. Enter the Python version: Specify the Python version required for your program (e.g., 3.10).
  2. 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

  1. 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.
  2. Runs the program while opening a command line window: Select this if your program lacks a GUI but includes interactive parts (e.g., input()).

The Easiest Way to Package Your Python Files(Turn to .exe Files)
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.

The Easiest Way to Package Your Python Files(Turn to .exe Files)

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.

The Easiest Way to Package Your Python Files(Turn to .exe Files)

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.

The Easiest Way to Package Your Python Files(Turn to .exe Files)

2. Package Multiple Python Files

The “Package multiple Python files” option allows users to package multiple .py files. Simply select their paths.
The Easiest Way to Package Your Python Files(Turn to .exe Files)

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does the choice between lists and arrays impact the overall performance of a Python application dealing with large datasets?How does the choice between lists and arrays impact the overall performance of a Python application dealing with large datasets?May 03, 2025 am 12:11 AM

ForhandlinglargedatasetsinPython,useNumPyarraysforbetterperformance.1)NumPyarraysarememory-efficientandfasterfornumericaloperations.2)Avoidunnecessarytypeconversions.3)Leveragevectorizationforreducedtimecomplexity.4)Managememoryusagewithefficientdata

Explain how memory is allocated for lists versus arrays in Python.Explain how memory is allocated for lists versus arrays in Python.May 03, 2025 am 12:10 AM

InPython,listsusedynamicmemoryallocationwithover-allocation,whileNumPyarraysallocatefixedmemory.1)Listsallocatemorememorythanneededinitially,resizingwhennecessary.2)NumPyarraysallocateexactmemoryforelements,offeringpredictableusagebutlessflexibility.

How do you specify the data type of elements in a Python array?How do you specify the data type of elements in a Python array?May 03, 2025 am 12:06 AM

InPython, YouCansSpectHedatatYPeyFeLeMeReModelerErnSpAnT.1) UsenPyNeRnRump.1) UsenPyNeRp.DLOATP.PLOATM64, Formor PrecisconTrolatatypes.

What is NumPy, and why is it important for numerical computing in Python?What is NumPy, and why is it important for numerical computing in Python?May 03, 2025 am 12:03 AM

NumPyisessentialfornumericalcomputinginPythonduetoitsspeed,memoryefficiency,andcomprehensivemathematicalfunctions.1)It'sfastbecauseitperformsoperationsinC.2)NumPyarraysaremorememory-efficientthanPythonlists.3)Itoffersawiderangeofmathematicaloperation

Discuss the concept of 'contiguous memory allocation' and its importance for arrays.Discuss the concept of 'contiguous memory allocation' and its importance for arrays.May 03, 2025 am 12:01 AM

Contiguousmemoryallocationiscrucialforarraysbecauseitallowsforefficientandfastelementaccess.1)Itenablesconstanttimeaccess,O(1),duetodirectaddresscalculation.2)Itimprovescacheefficiencybyallowingmultipleelementfetchespercacheline.3)Itsimplifiesmemorym

How do you slice a Python list?How do you slice a Python list?May 02, 2025 am 12:14 AM

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

What are some common operations that can be performed on NumPy arrays?What are some common operations that can be performed on NumPy arrays?May 02, 2025 am 12:09 AM

NumPyallowsforvariousoperationsonarrays:1)Basicarithmeticlikeaddition,subtraction,multiplication,anddivision;2)Advancedoperationssuchasmatrixmultiplication;3)Element-wiseoperationswithoutexplicitloops;4)Arrayindexingandslicingfordatamanipulation;5)Ag

How are arrays used in data analysis with Python?How are arrays used in data analysis with Python?May 02, 2025 am 12:09 AM

ArraysinPython,particularlythroughNumPyandPandas,areessentialfordataanalysis,offeringspeedandefficiency.1)NumPyarraysenableefficienthandlingoflargedatasetsandcomplexoperationslikemovingaverages.2)PandasextendsNumPy'scapabilitieswithDataFramesforstruc

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version