Skip to content

Commit 618cfba

Browse files
Fix PyCANDYAlgo runtime library dependencies
- Add LD_LIBRARY_PATH setup for MKL and torch libraries in deploy.sh - Inject library path settings into virtualenv activate script - Add detailed error logging with ldd check and traceback - Update GitHub Actions workflow to set LD_LIBRARY_PATH before import tests This fixes the import error in GitHub Actions caused by missing runtime library paths.
1 parent dd2a3f4 commit 618cfba

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

.github/workflows/build-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ jobs:
4545
- name: Verify Python packages
4646
run: |
4747
source sage-db-bench/bin/activate
48+
# 设置库路径
49+
TORCH_LIB=$(python -c "import torch; import os; print(os.path.join(os.path.dirname(torch.__file__), 'lib'))")
50+
export LD_LIBRARY_PATH="$TORCH_LIB:$LD_LIBRARY_PATH"
51+
52+
# 测试导入
4853
python -c "import PyCANDYAlgo; print('✓ PyCANDYAlgo imported')"
4954
python -c "import pyvsag; print('✓ pyvsag imported')"
5055
python -c "import numpy, torch, yaml; print('✓ Core dependencies OK')"

deploy.sh

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,38 @@ cd "$SCRIPT_DIR/algorithms_impl"
368368
print_step "安装 PyCANDYAlgo..."
369369
SO_FILE=$(ls PyCANDYAlgo*.so 2>/dev/null | head -1)
370370
if [ -n "$SO_FILE" ] && [ -f "setup.py" ]; then
371+
# 设置运行时库路径
372+
if [ -d "/opt/intel/oneapi/mkl/latest/lib/intel64" ]; then
373+
export LD_LIBRARY_PATH="/opt/intel/oneapi/mkl/latest/lib/intel64:$LD_LIBRARY_PATH"
374+
fi
375+
376+
# 添加 torch 库路径
377+
TORCH_LIB=$(python3 -c "import torch; import os; print(os.path.join(os.path.dirname(torch.__file__), 'lib'))" 2>/dev/null)
378+
if [ -n "$TORCH_LIB" ] && [ -d "$TORCH_LIB" ]; then
379+
export LD_LIBRARY_PATH="$TORCH_LIB:$LD_LIBRARY_PATH"
380+
fi
381+
371382
pip install -e . --no-build-isolation
372383
print_success "PyCANDYAlgo 已安装"
384+
385+
# 保存库路径到 activate 脚本
386+
VENV_ACTIVATE="$SCRIPT_DIR/sage-db-bench/bin/activate"
387+
if [ -f "$VENV_ACTIVATE" ]; then
388+
# 在 activate 脚本中添加 LD_LIBRARY_PATH 设置
389+
if ! grep -q "# PyCANDYAlgo library paths" "$VENV_ACTIVATE"; then
390+
cat >> "$VENV_ACTIVATE" << 'ACTIVATE_EOF'
391+
392+
# PyCANDYAlgo library paths
393+
if [ -d "/opt/intel/oneapi/mkl/latest/lib/intel64" ]; then
394+
export LD_LIBRARY_PATH="/opt/intel/oneapi/mkl/latest/lib/intel64:$LD_LIBRARY_PATH"
395+
fi
396+
TORCH_LIB=$(python3 -c "import torch; import os; print(os.path.join(os.path.dirname(torch.__file__), 'lib'))" 2>/dev/null)
397+
if [ -n "$TORCH_LIB" ] && [ -d "$TORCH_LIB" ]; then
398+
export LD_LIBRARY_PATH="$TORCH_LIB:$LD_LIBRARY_PATH"
399+
fi
400+
ACTIVATE_EOF
401+
fi
402+
fi
373403
else
374404
print_warning "PyCANDYAlgo.so 未找到,跳过安装"
375405
fi
@@ -397,19 +427,43 @@ print_header "步骤 7/7: 验证安装"
397427

398428
print_step "测试 Python 包导入..."
399429

430+
# 设置运行时库路径
431+
if [ -d "/opt/intel/oneapi/mkl/latest/lib/intel64" ]; then
432+
export LD_LIBRARY_PATH="/opt/intel/oneapi/mkl/latest/lib/intel64:$LD_LIBRARY_PATH"
433+
fi
434+
TORCH_LIB=$(python3 -c "import torch; import os; print(os.path.join(os.path.dirname(torch.__file__), 'lib'))" 2>/dev/null)
435+
if [ -n "$TORCH_LIB" ] && [ -d "$TORCH_LIB" ]; then
436+
export LD_LIBRARY_PATH="$TORCH_LIB:$LD_LIBRARY_PATH"
437+
fi
438+
400439
# 测试 PyCANDYAlgo - 使用更详细的错误信息
401440
echo "正在测试 PyCANDYAlgo 导入..."
441+
442+
# 首先检查 .so 文件是否存在
443+
SO_FILE=$(find algorithms_impl -name "PyCANDYAlgo*.so" 2>/dev/null | head -1)
444+
if [ -n "$SO_FILE" ]; then
445+
print_info "找到 .so 文件: $SO_FILE"
446+
# 检查依赖库
447+
print_info "检查依赖库..."
448+
ldd "$SO_FILE" | grep "not found" || echo " 所有依赖库都已找到"
449+
else
450+
print_warning "未找到 PyCANDYAlgo.so 文件"
451+
fi
452+
402453
PYCANDY_TEST=$(python3 << 'PYEOF'
403454
import sys
455+
import traceback
404456
try:
405457
import PyCANDYAlgo
406458
print("SUCCESS")
407459
sys.exit(0)
408460
except ImportError as e:
409461
print(f"IMPORT_ERROR: {e}")
462+
traceback.print_exc()
410463
sys.exit(1)
411464
except Exception as e:
412465
print(f"OTHER_ERROR: {e}")
466+
traceback.print_exc()
413467
sys.exit(2)
414468
PYEOF
415469
)
@@ -418,12 +472,13 @@ if echo "$PYCANDY_TEST" | grep -q "SUCCESS"; then
418472
print_success "PyCANDYAlgo 导入成功"
419473
else
420474
print_warning "PyCANDYAlgo 导入失败"
421-
echo "$PYCANDY_TEST" | head -3
475+
echo "$PYCANDY_TEST"
422476
echo ""
423477
print_info "可能的解决方案:"
424478
echo " 1. 检查 .so 文件是否存在: find algorithms_impl -name '*.so'"
425479
echo " 2. 手动测试: python3 -c 'import PyCANDYAlgo'"
426480
echo " 3. 查看详细错误: python3 -c 'import PyCANDYAlgo' 2>&1"
481+
echo " 4. 检查依赖库: ldd \$(find algorithms_impl -name 'PyCANDYAlgo*.so')"
427482
fi
428483

429484
# 测试 pyvsag

0 commit comments

Comments
 (0)