Technology Sharing

Python program packaging .exe file

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina


When we develop a deep learning program, we often run the code on another computer and have to continue to install the dependencies of the deep learning environment. However, packaging the entire code program into an .exe file will also package the modules, libraries, resource files, etc. that the program depends on.

1. cxfreeze

The principle of cxfreeze is to package the Python program and its dependent modules, libraries, resource files, etc. into an executable file. During the packaging process, cxfreeze will package the Python interpreter and program code together, and also package the modules, libraries, resource files, etc. that the program depends on. When the program is running, cxfreeze will decompress these files and run the program in the decompressed folder.

# 1.1 Install cxfreeze

pip install cx_Freeze
  • 1

1.2 Create setup.py file

其实主要就是将executables里换成你的主函数入口
  • 1
from cx_Freeze import setup, Executable

setup(
    name="flooring",
    version="1.0",
    description="flooring exe",
    executables=[Executable("my_windows.py")]
)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

1.3 Generate .exe

python setup.py build
  • 1