""" Script to build Windows executable using PyInstaller Run this on a Windows machine or use Wine on Linux """ import os import sys import subprocess def build_executable(): """Build the Windows executable""" print("Building Windows executable with PyInstaller...") print("Note: For best results, build on a Windows machine") print() # Check if icon file exists icon_param = [] if os.path.exists('app_icon.ico'): icon_param = ['--icon=app_icon.ico'] print("Using icon file: app_icon.ico") else: print("No icon file found (optional)") # Locate mysql connector locales inside the venv import site venv_site = os.path.join('venv', 'Lib', 'site-packages') mysql_locales = os.path.join(venv_site, 'mysql', 'connector', 'locales') add_data_sep = ';' if sys.platform == 'win32' else ':' mysql_locales_arg = f'--add-data={mysql_locales}{add_data_sep}mysql/connector/locales' # PyInstaller command - simplified to avoid module collection issues cmd = [ 'pyinstaller', '--name=DatabaseApp', '--onefile', '--windowed', '--hidden-import=mysql.connector', '--hidden-import=mysql.connector.locales', '--hidden-import=mysql.connector.locales.eng', '--hidden-import=mysql.connector.plugins', '--hidden-import=mysql.connector.plugins.mysql_native_password', '--hidden-import=mysql.connector.plugins.caching_sha2_password', '--hidden-import=kivy.core.window.window_sdl2', '--hidden-import=win32timezone', '--exclude-module=_tkinter', '--exclude-module=matplotlib', '--exclude-module=numpy', mysql_locales_arg, ] + icon_param + ['main.py'] try: print("Running PyInstaller...") print("Command:", ' '.join(cmd)) print() subprocess.run(cmd, check=True) print("\n" + "="*50) print("Build completed successfully!") print("Executable location: dist/DatabaseApp.exe") print("="*50) print("\nNote: If the executable doesn't work on Windows:") print("1. Build it directly on a Windows machine") print("2. Use the DatabaseApp.spec file: pyinstaller DatabaseApp.spec") except subprocess.CalledProcessError as e: print(f"\nError building executable: {e}") print("\nTroubleshooting:") print("1. Make sure you're building on Windows for best compatibility") print("2. Try using the spec file: pyinstaller DatabaseApp.spec") print("3. Check BUILD_WINDOWS_GUIDE.md for more information") sys.exit(1) except FileNotFoundError: print("PyInstaller not found. Please install it first:") print("pip install pyinstaller") sys.exit(1) if __name__ == "__main__": build_executable()