# Bag3 / Bag4 Windows exe build (run all commands in this python/ folder)

py -m pip install --upgrade pyinstaller
py -m pip install --upgrade pywin32
py -m pip install --upgrade Pillow "qrcode[pil]" requests pyserial

# --- Bag4 (DataFlex with expiry) ---
py -m PyInstaller --noconfirm --clean Bag4.spec
# Output: dist\Bag4.exe  (one-file). Copy Bag4.exe to the client PC.
# Settings are created next to the exe: bag4_settings.json
# Do not overwrite Bag3.exe; Bag3 and Bag4 are separate.

# --- Bag3 (DataFlex without expiry) ---
py -m PyInstaller --noconfirm --clean Bag3.spec
# Output: dist\Bag3.exe

# --- If the client exe flashes and closes ---

1) On the client PC, open cmd in the folder that contains the exe and run:
   Bag4.exe
   You should see the error in the console, or open bag4_startup_error.log next to Bag4.exe.
   (Bag3: bag3_startup_error.log)

2) Compare BUILD machines (both should match):
   py --version
   py -m PyInstaller --version
   py -m pip show pyinstaller pywin32 Pillow qrcode requests pyserial

   A broken build is often caused by:
   - Different Python major version (e.g. 3.13 vs 3.11)
   - Incomplete tkinter on that Python (Store Python / partial install)
   - Old PyInstaller missing Tcl/Tk files in the bundle

3) Rebuild on the machine that works, or reinstall Python from python.org (64-bit)
   and reinstall deps above, then rebuild.

4) Spec files disable UPX (upx=False) for stability; do not re-enable unless you test on the client.

5) Client needs 64-bit Windows and Microsoft VC++ Redistributable (same as your Python installer).

6) Antivirus may quarantine the exe — whitelist the folder if the log mentions missing DLL.
