|
|
|
|
@ -1,111 +0,0 @@
|
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""
|
|
|
|
|
MagicWord 应用程序最终修复方案
|
|
|
|
|
使用macOS特定的库路径解决方案
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import platform
|
|
|
|
|
|
|
|
|
|
# 获取项目根目录
|
|
|
|
|
project_root = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
# 添加src目录到Python路径
|
|
|
|
|
sys.path.insert(0, os.path.join(project_root, 'src'))
|
|
|
|
|
|
|
|
|
|
# Qt路径设置
|
|
|
|
|
qt_path = os.path.join(project_root, '.venv', 'lib', 'python3.9', 'site-packages', 'PyQt5', 'Qt5')
|
|
|
|
|
qt_plugins_path = os.path.join(qt_path, 'plugins')
|
|
|
|
|
qt_lib_path = os.path.join(qt_path, 'lib')
|
|
|
|
|
|
|
|
|
|
print(f"项目根目录: {project_root}")
|
|
|
|
|
print(f"Qt路径: {qt_path}")
|
|
|
|
|
|
|
|
|
|
# macOS特定的环境变量设置
|
|
|
|
|
if platform.system() == "Darwin":
|
|
|
|
|
# 设置Qt插件路径
|
|
|
|
|
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = qt_plugins_path
|
|
|
|
|
|
|
|
|
|
# 关键:设置DYLD_FALLBACK_LIBRARY_PATH,这是macOS的库搜索后备路径
|
|
|
|
|
fallback_paths = [
|
|
|
|
|
qt_lib_path,
|
|
|
|
|
'/usr/local/lib',
|
|
|
|
|
'/usr/lib',
|
|
|
|
|
'/System/Library/Frameworks'
|
|
|
|
|
]
|
|
|
|
|
os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = ':'.join(fallback_paths)
|
|
|
|
|
|
|
|
|
|
# 设置其他环境变量
|
|
|
|
|
os.environ['DYLD_LIBRARY_PATH'] = qt_lib_path
|
|
|
|
|
os.environ['DYLD_FRAMEWORK_PATH'] = qt_lib_path
|
|
|
|
|
os.environ['QT_PREFIX_PATH'] = qt_path
|
|
|
|
|
os.environ['QT_DEBUG_PLUGINS'] = '1'
|
|
|
|
|
|
|
|
|
|
print("macOS环境变量设置完成:")
|
|
|
|
|
print(f"DYLD_FALLBACK_LIBRARY_PATH: {os.environ['DYLD_FALLBACK_LIBRARY_PATH']}")
|
|
|
|
|
print(f"QT_QPA_PLATFORM_PLUGIN_PATH: {os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']}")
|
|
|
|
|
|
|
|
|
|
print("\\n开始导入PyQt5...")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# 导入PyQt5
|
|
|
|
|
from PyQt5.QtWidgets import QApplication
|
|
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
|
print("✓ PyQt5导入成功")
|
|
|
|
|
|
|
|
|
|
# 启用高DPI支持
|
|
|
|
|
if hasattr(Qt, 'AA_EnableHighDpiScaling'):
|
|
|
|
|
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
|
|
|
|
|
if hasattr(Qt, 'AA_UseHighDpiPixmaps'):
|
|
|
|
|
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
|
|
|
|
|
|
|
|
|
|
# 创建QApplication
|
|
|
|
|
print("创建QApplication...")
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
app.setApplicationName("MagicWord")
|
|
|
|
|
app.setApplicationVersion("1.0")
|
|
|
|
|
print("✓ QApplication创建成功")
|
|
|
|
|
|
|
|
|
|
# 导入应用程序模块
|
|
|
|
|
print("导入应用程序模块...")
|
|
|
|
|
from word_main_window import WordStyleMainWindow
|
|
|
|
|
from settings.settings_manager import SettingsManager
|
|
|
|
|
print("✓ 应用程序模块导入成功")
|
|
|
|
|
|
|
|
|
|
# 创建设置管理器
|
|
|
|
|
settings_manager = SettingsManager()
|
|
|
|
|
|
|
|
|
|
# 创建主窗口
|
|
|
|
|
print("创建主窗口...")
|
|
|
|
|
main_window = WordStyleMainWindow()
|
|
|
|
|
main_window.show()
|
|
|
|
|
print("✓ 主窗口创建成功")
|
|
|
|
|
|
|
|
|
|
print("\\n🎉 应用程序启动成功!")
|
|
|
|
|
print("正在运行应用程序...")
|
|
|
|
|
|
|
|
|
|
# 运行应用程序
|
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"\\n❌ 错误: {e}")
|
|
|
|
|
import traceback
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
# 如果失败,尝试使用系统Qt
|
|
|
|
|
print("\\n尝试使用系统Qt...")
|
|
|
|
|
try:
|
|
|
|
|
# 清除自定义环境变量
|
|
|
|
|
for key in ['QT_QPA_PLATFORM_PLUGIN_PATH', 'DYLD_LIBRARY_PATH',
|
|
|
|
|
'DYLD_FRAMEWORK_PATH', 'DYLD_FALLBACK_LIBRARY_PATH']:
|
|
|
|
|
if key in os.environ:
|
|
|
|
|
del os.environ[key]
|
|
|
|
|
|
|
|
|
|
from PyQt5.QtWidgets import QApplication
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
print("✓ 使用系统Qt成功")
|
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
except Exception as e2:
|
|
|
|
|
print(f"❌ 系统Qt也失败: {e2}")
|
|
|
|
|
sys.exit(1)
|