Build Python thành file EXE chạy trên window

27/04/2026
build-python-thanh-file-exe-chay-tren-window

Build Python thành file EXE chạy trên window

Bước 1: Copy chương trình Python đã chạy vào chatGPT và thêm cú pháp:

"đóng gói chương trình python thành file setup exe có giao diện: chọn cổng camera kết nối, chọn cổng gửi tín hiệu sang serial cho arduino, nút start và stop để bắt đầu quét mầu, có thông báo bằng chữ 3 Mầu đỏ,vàng, xanh trên màn hình"

Cú pháp phải đủ ý như trên

Bước 2: Tạo file: tomato_app.py (Tên file rất quan trọng để có lệnh build file đó)

Paste nội dung chatGPT đã gửi sang

Bước 3: Lệnh cài thư viện trong terminal:

pip install opencv-python pyserial pillow

Bước 4: Build thành file EXE

Cài PyInstaller:      pip install pyinstaller

Build:                     pyinstaller --onefile --windowed tomato_app.py

Sau khi build xong:

Bạn sẽ thấy file: (trong thư mục dist)

dist/tomato_app.exe

Bước 5: Tạo file Setup cài đặt (quan trọng 🔥)

Dùng phần mềm: Inno Setup (chuẩn nhất).

Tải: https://jrsoftware.org/isdl.php

Cài xong → mở Inno Setup → chọn Create new script

Dán script sau:

[Setup]
AppName=Tomato Detector
AppVersion=1.0
DefaultDirName={pf}\TomatoDetector
DefaultGroupName=Tomato Detector
OutputDir=output
OutputBaseFilename=TomatoSetup
Compression=lzma
SolidCompression=yes

[Files]
Source: "dist\tomato_app.exe"; DestDir: "{app}"; Flags: ignoreversion

[Icons]
Name: "{group}\Tomato Detector"; Filename: "{app}\tomato_app.exe"
Name: "{commondesktop}\Tomato Detector"; Filename: "{app}\tomato_app.exe"

Nhấn Build → Compile

👉 Bạn sẽ có file:

TomatoSetup.exe

Đây là file setup cài đặt chuyên nghiệp 🎉

Bình luận
Nội dung này chưa có bình luận, hãy gửi bình luận đầu tiên của bạn.
VIẾT BÌNH LUẬN CỦA BẠN