This commit is contained in:
wzy-warehouse
2026-06-20 17:20:36 +08:00
parent f1e85468c5
commit 7d67096cb6
2 changed files with 44 additions and 14 deletions
+21 -1
View File
@@ -111,7 +111,23 @@ def get_runner_script() -> str:
def _generate_bat_wrapper(qgis_root: str, python_path: str, runner_script: str) -> str:
"""生成 .bat 包装脚本,设置 QGIS 环境变量并启动 runner"""
qgis_app_dir = os.path.join(qgis_root, "apps", "qgis-ltr").replace("/", "\\")
# 自动检测 QGIS 应用目录(qgis-ltr 或 qgis
qgis_app_dir = os.path.join(qgis_root, "apps", "qgis-ltr")
if not os.path.isdir(qgis_app_dir):
qgis_app_dir = os.path.join(qgis_root, "apps", "qgis")
qgis_app_dir = qgis_app_dir.replace("/", "\\")
# 自动检测 PROJ 目录
proj_data = ""
for pd in [
os.path.join(qgis_app_dir, "share", "proj"),
os.path.join(qgis_root, "share", "proj"),
os.path.join(qgis_root, "apps", "gdal", "share", "proj"),
]:
if os.path.isfile(os.path.join(pd, "proj.db")):
proj_data = pd.replace("/", "\\")
break
python_dir = os.path.join(qgis_root, "apps", "Python312").replace("/", "\\")
qt5_plugins = os.path.join(qgis_root, "apps", "Qt5", "plugins").replace("/", "\\")
qtplugins = os.path.join(qgis_app_dir, "qtplugins").replace("/", "\\")
@@ -121,12 +137,16 @@ def _generate_bat_wrapper(qgis_root: str, python_path: str, runner_script: str)
qt5_bin = os.path.join(qgis_root, "apps", "Qt5", "bin").replace("/", "\\")
gdal_lib = os.path.join(qgis_root, "apps", "gdal", "lib").replace("/", "\\")
proj_line = f'set "PROJ_DATA={proj_data}"' if proj_data else "REM PROJ_DATA not found"
bat_content = f"""@echo off
chcp 65001 >nul
set "PYTHONHOME={python_dir}"
set "PYTHONPATH={qgis_python_dir}"
set "QGIS_PREFIX_PATH={qgis_app_dir}"
set "QT_PLUGIN_PATH={qtplugins};{qt5_plugins}"
set "GDAL_DATA={gdal_data}"
{proj_line}
set "PYTHONUTF8=1"
set "GDAL_FILENAME_IS_UTF8=YES"
set "VSI_CACHE=TRUE"