This guide documents the process of creating a standalone executable for the X-Plane Dataref Bridge (XPDRB) application, including solutions for common dependency issues.
The X-Plane Dataref Bridge application is a Python/PyQt6 application that requires special handling during packaging due to its dependencies on serial communication libraries, PyQt6, and qasync for asynchronous operations.
The most common issue during packaging is the "No module named 'qasync'" error, which occurs because packaging tools sometimes fail to detect all dependencies automatically.
-
Install PyInstaller:
```bash
pip install pyinstaller
``` -
Create executable with proper hidden imports:
```bash
pyinstaller --onefile --windowed --icon=resources/icon.ico --hidden-import=serial --hidden-import=serial.tools --hidden-import=serial.tools.list_ports --hidden-import=PyQt6 --hidden-import=PyQt6.QtCore --hidden-import=PyQt6.QtGui --hidden-import=PyQt6.QtWidgets --hidden-import=qasync main.py
```
-
Create a setup script (`setup_cx.py`:
```python
import sys
from cx_Freeze import setup, Executablebuild_exe_options = {
"packages": [
'serial',
'serial.tools',
'serial.tools.list_ports',
'serial.serialwin32',
'serial.win32',
'serial.serialutil',
'serial.threaded',
'qasync',
'PyQt6',
],
"includes": [
'serial.serialutil',
'serial.threaded',
'serial.urlhandler',
'serial.urlhandler.protocol_socket',
'serial.urlhandler.protocol_rfc2217',
'serial.urlhandler.protocol_loop',
'serial.urlhandler.protocol_alt',
'serial.urlhandler.protocol_cp2110',
'serial.urlhandler.protocol_hwgrep',
'serial.urlhandler.protocol_spy',
],
"excludes": [],
"optimize": 0,
}if sys.platform == "win32":
base = "Win32GUI" # Use 'Win32GUI' for Windows GUI applications
else:
base = Nonesetup(
name="X-Plane Dataref Bridge",
version="1.0",
description="X-Plane Dataref Bridge",
options={"build_exe": build_exe_options},
executables=[Executable("main.py", base=base, icon="resources/icon.ico",
target_name="X-Plane Dataref Bridge.exe")]
)
``` -
Install cx_Freeze:
```bash
pip install cx_Freeze
``` -
Build the executable:
```bash
python setup_cx.py build
```
Two executables were successfully created:
-
PyInstaller executable (main.exe):
- Located in the dist folder
- Size: ~38MB
- Contains all dependencies in a single file
-
cx_Freeze executable (X-Plane Dataref Bridge.exe):
- Located in the build\\exe.win-amd64-3.14 folder
- Size: ~29KB (with supporting files in the lib directory)
- Properly includes all required modules (qasync, serial, PyQt6 components)
For distribution, you can use either:
- The PyInstaller version: Simply distribute the single main.exe file
- The cx_Freeze version: Distribute the entire build\\exe.win-amd64-3.14 folder
Both executables will run on Windows systems without requiring Python or any installed packages.
- If you encounter missing module errors, ensure all dependencies are listed in the setup script
- For PyQt6 applications, make sure to include all relevant Qt modules
- For serial communication, include all serial submodules and backends
- Use the --windowed flag for GUI applications to prevent console window from appearing