导入PyTorch时触发OSError错误的问题排查及解决
PyTorch导入报错WinError 126:shm.dll依赖找不到的解决办法
问题现象
导入PyTorch时抛出如下错误,且确认shm.dll文件确实存在于报错提示的路径中:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\User\AppData\Roaming\Python\Python312\site-packages\torch\__init__.py", line 141, in <module> raise err OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\User\AppData\Roaming\Python\Python312\site-packages\torch\lib\shm.dll" or one of its dependencies.
已尝试的无效方案
- 检查并确认
shm.dll文件存在于指定路径 - 执行
pip3 install torch torchvision torchaudio重新安装PyTorch及其关联库
可行解决方案
将\AppData\Roaming\Python\Library\bin(替换为对应用户目录的完整路径)添加到系统PATH环境变量中,重启终端或开发环境后,PyTorch即可正常导入。
内容的提问来源于stack exchange,提问作者user23247397
相关产品推荐
相关产品推荐

