import sys
import os

print("=" * 60)
print("QGIS 环境诊断")
print("=" * 60)

print(f"\n1. Python 解释器路径: {sys.executable}")

print(f"\n2. Python 版本: {sys.version}")

print(f"\n3. sys.path (Python 搜索路径):")
for i, p in enumerate(sys.path):
    print(f"   [{i}] {p}")

print(f"\n4. 检查关键目录是否存在:")
key_paths = [
    r"D:\Program Files\QGIS 3.44.9\apps\Python312\Lib\site-packages\PyQt5",
    r"D:\Program Files\QGIS 3.44.9\apps\qgis-ltr\python\qgis",
]

for p in key_paths:
    exists = os.path.exists(p)
    print(f"   {'✓' if exists else '✗'} {p}")

print(f"\n5. 尝试导入:")
try:
    import PyQt5
    print(f"   ✓ PyQt5 导入成功, 位置: {PyQt5.__file__}")
except ImportError as e:
    print(f"   ✗ PyQt5 导入失败: {e}")

try:
    from PyQt5.QtCore import QThread
    print(f"   ✓ from PyQt5.QtCore import QThread 成功")
except ImportError as e:
    print(f"   ✗ from PyQt5.QtCore import QThread 失败: {e}")

try:
    from qgis.core import QgsGeometry
    print(f"   ✓ from qgis.core import QgsGeometry 成功")
except ImportError as e:
    print(f"   ✗ from qgis.core import QgsGeometry 失败: {e}")