在安装ISAT_with_segment_anything配置环境运行时,本地 Windows 环境部署时启动失败的问题,主要原因是VC++运行库(c10.dll加载失败)和PyTorch版本匹配两个问题。

我的环境:windows11+python3.10.4,建议使用虚拟环境

详细的报错原因:OSError: [WinError 1114] 动态链接库(DLL)初始化例程失败。 Error loading "D:\Python\isat_env\lib\site-packages\torch\lib\c10.dll" or one of its dependencies.如图所示:


一:VC++ 运行库缺失导致 c10.dll 加载失败(我觉得大概率不是这个的问题)

这是 Windows 下 PyTorch 最常见的坑。PyTorch 的核心组件 c10.dll(Caffe2 and Torch 的底层抽象层)依赖 Microsoft Visual C++ 运行库,如果系统没有安装对应版本的 VC++ Redistributable,就会报 DLL 初始化失败。

检查方法:

  1. 打开「控制面板」→「程序和功能」
  2. 查找是否安装了 Microsoft Visual C++ 2015-2022 Redistributable (x64)
  3. 如果没有,或版本较旧,去微软官网下载最新版 vc_redist.x64.exe 安装,如果显示已经安装了,把之前的版本全部卸载然后安装上面2015-2022版本
  4. 安装完成后重启电脑

二:PyTorch 三件套版本严重不匹配

执行 pip list | Select-String torch 查看当前torch,torchvision,torchaudio的版本,很大概率是版本不匹配。PyTorch 生态遵循"主版本对齐"原则,三者版本错位会导致 API 不兼容、模型加载失败甚至静默崩溃。

解决方法: 彻底卸载后重装配套版本

如何选择相应的版本号,可以直接问AI

# 卸载干净(执行两遍确保无残留)
pip uninstall torch torchvision torchaudio -y
pip uninstall torch torchvision torchaudio -y

# 安装配套版本(CPU 版)这是我的版本
pip install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cpu

装完后验证:

python -c "import torch; import torchvision; import torchaudio; print(torch.__version__, torchvision.__version__, torchaudio.__version__)"

正常输出 2.4.1+cpu 0.19.1+cpu 2.4.1+cpu 即表示版本已对齐。

再次执行python main.py,结果如下所示:

更多推荐