This document explains how to package main.py and main_sse.py into standalone executable files.
build_main.spec- PyInstaller configuration file for packagingmain.pybuild_main_sse.spec- PyInstaller configuration file for packagingmain_sse.py
build.bat- Windows batch script for automated build processbuild.ps1- PowerShell script for automated build process (Windows recommended)build.sh- Shell script for automated build process (macOS recommended)
- Double-click to run
build.bat - The script will automatically:
- Check and install PyInstaller (if not installed)
- Clean previous build files
- Package both programs sequentially
- Display build results
- Right-click
build.ps1and select "Run with PowerShell" - Or execute in PowerShell:
.\build.ps1
If the automated scripts encounter issues, you can manually execute the following commands:
# Install PyInstaller (if not installed)
pip install pyinstaller
# Clean previous build files
rmdir /s /q dist
rmdir /s /q build
# Package main.py
pyinstaller build_main.spec --clean --noconfirm
# Package main_sse.py
pyinstaller build_main_sse.spec --clean --noconfirm- Open terminal and navigate to project directory
- Execute the following commands:
chmod +x build.sh
./build.sh- The script will automatically:
- Check and install PyInstaller (if not installed)
- Clean previous build files
- Package both programs sequentially
- Display build results
If the automated script encounters issues, you can manually execute the following commands:
# Install PyInstaller (if not installed)
pip3 install pyinstaller
# Clean previous build files
rm -rf dist
rm -rf build
# Package main.py
pyinstaller build_main.spec --clean --noconfirm
# Package main_sse.py
pyinstaller build_main_sse.spec --clean --noconfirmAfter successful packaging, two executable files will be generated in the dist directory:
UserBank_Stdio_Core.exe- Standard MCP server based onmain.pyUserBank_SSE_Core.exe- SSE mode server based onmain_sse.py
After successful packaging, two executable files will be generated in the dist directory:
UserBank_Stdio_Core- Standard MCP server based onmain.pyUserBank_SSE_Core- SSE mode server based onmain_sse.py
- This is the standard MCP server
- Double-click to run and start the server
- Suitable for MCP client connections
- This is the SSE mode HTTP server
- Double-click to start the web server
- Default listening port is determined by configuration file
- Supports CORS and can be accessed through browsers
- This is the standard MCP server
- Run in terminal:
./dist/UserBank_Stdio_Core - Suitable for MCP client connections
- This is the SSE mode HTTP server
- Run in terminal:
./dist/UserBank_SSE_Core - Default listening port is determined by configuration file
- Supports CORS and can be accessed through browsers
-
Dependency Inclusion: The packaging process automatically includes all necessary dependency files:
toolsdirectory and all its modulesconfig_manager.pyconfiguration managerDatabasedirectory (if exists)
-
Hidden Imports: Configuration files include all necessary hidden imports to ensure no module missing issues at runtime
-
File Size: Generated executable files may be large (typically 50-100MB), which is normal as they contain the complete Python runtime and all dependencies
-
Runtime Environment:
- Windows: Generated exe files can run on any Windows machine without requiring Python installation
- macOS: Generated executables can run on any macOS machine without requiring Python installation
-
Configuration Files: Ensure configuration files and database files are in the same directory as the executable files or in correct relative paths
- Ensure all dependencies are properly installed:
- Windows:
pip install -r requirements.txt - macOS:
pip3 install -r requirements.txt
- Windows:
- Check for syntax errors or import errors
- Review PyInstaller's detailed error messages
- Check if configuration file paths are correct
- Ensure database files exist and are accessible
- Review error messages in console/terminal output
- Module Not Found: Check if
hiddenimportslist includes all necessary modules - File Path Errors: Ensure file paths in
dataslist are correct - Permission Issues:
- Windows: Ensure sufficient permissions to create and run exe files
- macOS: Ensure sufficient permissions to create and run executables, may need to use
chmod +xcommand
If you need to modify the packaging configuration, you can edit the .spec files:
- Modify the
namefield to change output filename - Add
iconfield to set program icon - Modify
consolefield to control console window visibility - Add additional data files in
datas - Add additional hidden import modules in
hiddenimports
- Code Signing:
- Windows: Digital certificate signing recommended
- macOS: Code signing recommended to avoid security warnings
- Permission Settings: Ensure application has appropriate file system access permissions
- Firewall Settings: If using SSE mode, ensure firewall allows application network access
- UPX Compression: UPX compression enabled by default to reduce file size
- Resource Optimization: Resource inclusion can be optimized by modifying
.specfiles - Launch Optimization: Launch time can be optimized by adjusting PyInstaller parameters