27 lines
1013 B
Python
27 lines
1013 B
Python
import os
|
|
import sys
|
|
|
|
# Fixing Qt Platform Plugin "windows" error for PyInstaller OneFile
|
|
# This runs BEFORE main.py
|
|
|
|
def install_qt_plugin_path():
|
|
# If running in a PyInstaller bundle
|
|
if getattr(sys, 'frozen', False):
|
|
# sys._MEIPASS is where PyInstaller unpacks the bundle
|
|
base_path = getattr(sys, '_MEIPASS', os.path.dirname(sys.executable))
|
|
|
|
# We bundled paths via "a.datas += Tree(..., prefix='platforms')"
|
|
# So it should be at base_path/platforms
|
|
platform_plugin_path = os.path.join(base_path, 'platforms')
|
|
|
|
print("runtime_hook: Detected base path: {}".format(base_path))
|
|
print("runtime_hook: Setting QT_QPA_PLATFORM_PLUGIN_PATH to: {}".format(platform_plugin_path))
|
|
|
|
# Force Qt to look here
|
|
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = platform_plugin_path
|
|
|
|
# Also ensure general plugin path is set, just in case
|
|
os.environ['QT_PLUGIN_PATH'] = base_path
|
|
|
|
install_qt_plugin_path()
|