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

torch_geometric调用Dataset子类get()方法时WinError127的解决方法咨询

问题场景

运行继承自pyg.data.Dataset的数据集类时触发OSError: [WinError 127],调用代码如下:

dataset_sample = OneStepDataset(OUTPUT_DIR, "valid", return_pos=True)
graph, position = dataset_sample[0]

报错追踪路径:

  1. 进入PyTorch Geometric的Dataset类代码(路径:C:\...\Python39\lib\site-packages\torch_geometric\data\dataset.py:197):
if (isinstance(idx, (int, np.integer))
    194         or (isinstance(idx, Tensor) and idx.dim() == 0)
    195         or (isinstance(idx, np.ndarray) and np.isscalar(idx))):
--> 197     data = self.get(self.indices()[idx])
    198     data = data if self.transform is None else self.transform(data)
    199     return data
  1. 后续追踪到动态链接库加载代码:
...
--> 374     self._handle = _dlopen(self._name, mode)
    375 else:
    376     self._handle = handle

最终报错:

OSError: [WinError 127] The specified procedure could not be found
可行解决方法
  • 检查PyTorch与PyTorch Geometric版本兼容性
    WinError127常因依赖库版本不匹配触发,尤其是PyTorch、CUDA、PyTorch Geometric及其依赖的torch-scatter、torch-sparse等组件版本不兼容。先确认本地PyTorch版本,再安装对应版本的PyG依赖,示例命令(适配PyTorch1.12+CUDA11.3):

    pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.12.0+cu113.html
    

    需替换为实际的PyTorch和CUDA版本。

  • 清理并重新安装依赖库
    卸载现有PyG相关库,清理缓存后重新安装:

    pip uninstall -y torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric
    pip cache purge
    # 重新安装对应版本的库
    
  • 排查自定义Dataset类的get()方法
    检查OneStepDataset的get()方法:

    • 是否有加载外部DLL/so文件的操作?确认文件路径正确且未损坏。
    • 是否调用了依赖特定版本的第三方库?比如某些科学计算库的C扩展版本不匹配。
  • 切换到Python虚拟环境
    全局环境可能存在依赖冲突,创建新虚拟环境重新安装PyTorch和PyG:

    python -m venv pyg_env
    # Windows激活环境
    pyg_env\Scripts\activate
    # 安装PyTorch
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
    # 安装对应版本的PyG
    pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-2.0.0+cu118.html
    
  • 检查系统环境变量
    确保系统PATH环境变量包含PyTorch的lib目录、CUDA的bin目录等依赖库所在路径,避免动态链接库加载时找不到文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 03:05:49