You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用LangChain+HuggingFaceInstructEmbeddings遇c10.dll模块找不到错误求助

问题解决:OSError: [WinError 126] 加载c10.dll失败

问题描述

结合HuggingFace与LangChain使用HuggingFaceInstructEmbeddings时,运行代码触发以下错误:

File "C:\Users\Nedal Ahmed\Desktop\QAQiwa\main.py", line 14, in <module>
    ins_embeddings = HuggingFaceInstructEmbeddings()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 126] The specified module could not be found. Error loading "c:\Users\Nedal Ahmed\Desktop\QAQiwa\.venv\Lib\site-packages\torch\lib\c10.dll" or one of its dependencies.

已执行以下命令但问题未解决:

pip install sentence-transformers==2.2.2
pip install InstructorEmbedding

解决方案

该错误核心是PyTorch核心依赖库c10.dll无法加载,多由Windows系统运行库缺失、PyTorch版本不兼容或虚拟环境损坏导致,按以下步骤排查修复:

1. 安装微软VC++ Redistributable运行库

c10.dll依赖微软Visual C++运行时库,直接安装对应版本:

  • 下载x64版本的Microsoft Visual C++ Redistributable(Windows 10/11优先选2022版),安装完成后重启电脑再测试代码。

2. 重新安装适配Windows的PyTorch

默认pip安装的PyTorch可能非Windows兼容版本,用官方命令重装:

# CPU版本(无GPU时推荐)
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

# NVIDIA GPU用户安装CUDA版本(需匹配本地CUDA版本,示例为11.8)
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

3. 重建虚拟环境

若虚拟环境文件损坏,删除旧环境后重新创建并安装依赖:

# 删除旧虚拟环境
rmdir /s .venv

# 创建新虚拟环境
python -m venv .venv

# 激活虚拟环境(Windows cmd)
.venv\Scripts\activate.bat

# 批量安装依赖
pip install langchain_community faiss-cpu openai sentence-transformers==2.2.2 InstructorEmbedding

4. 验证依赖版本兼容性

确保库版本匹配避免冲突:

  • 确认torch版本≥2.0.0
  • 保持sentence-transformers固定为2.2.2,与InstructorEmbedding兼容

代码补充说明

原代码需注意两点:

  • 需先调用create_vector_db()生成FAISS索引,否则get_qa_chain()加载索引会报错
  • OpenAI API密钥建议通过环境变量传递,不要硬编码在代码中

内容的提问来源于stack exchange,提问作者Nedal Ahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 16:43:28