From 39d4fc12d0150d42dbd7881c22e14f3f03f97e06 Mon Sep 17 00:00:00 2001 From: developer-wlj Date: Wed, 2 Sep 2026 20:06:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(main):=20=E8=A7=A3=E5=86=B3=20Windows=20Fre?= =?UTF-8?q?e-Threading=20=E7=8E=AF=E5=A2=83=E4=B8=8B=20DLL=20=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 shutil 模块导入用于查找可执行文件 - 为 Windows 环境手动注入 DLL 搜索路径 - 使用 shutil.which 查找 psql 可执行文件位置 - 将 psql 目录添加到 DLL 搜索路径以避免运行失败 - 针对 Python 3.8+ 的 DLL 加载行为变化进行适配 --- app/main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/main.py b/app/main.py index 75716a246..c85fdc669 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,14 @@ import os +import shutil import sys +# Windows 环境下手动注入 DLL 搜索路径 +# Python 3.8+ 不再从环境变量 PATH 中自动加载 DLL。由于 psycopg 在 Free-Threading 版本中强制使用 C 扩展, +# 为避免因缺少底层 C 库导致运行失败,必须手动将 psql 所在目录加入 DLL 搜索路径。 +if os.name == "nt": + psql_exe = shutil.which("psql") + if psql_exe: + os.add_dll_directory(os.path.dirname(psql_exe)) def _prepare_direct_execution_import_path() -> None: """