OSError: libcudart.so.11.0: cannot open shared object file: No such file or directory

OSError: libcudart.so.11.0: cannot open shared object file: No such file or directory

  • 完美解决:OSError: libcudart.so.11.0: cannot open shared object file: No such file or directory
  • OSError: libcudart.so.11.0: cannot open shared object file: No such file or directory
    • 环境
    • 错误详情
    • 错误原因
    • 错误排查
    • 解决方法
    • 验证
  • 参考

完美解决:OSError: libcudart.so.11.0: cannot open shared object file: No such file or directory

OSError: libcudart.so.11.0: cannot open shared object file: No such file or directory

环境

  • Ubuntu 22.04 LTS
  • python 3.9
  • torch 1.11.0

错误详情

运行 python train.py 报错如下:

  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/lightning_utilities/core/imports.py", line 77, in compare_version
    pkg = importlib.import_module(package)
  File "/data/miniconda3/envs/py39/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/__init__.py", line 1, in 
    from torchaudio import (  # noqa: F401
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/_extension.py", line 135, in 
    _init_extension()
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/_extension.py", line 105, in _init_extension
    _load_lib("libtorchaudio")
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/_extension.py", line 52, in _load_lib
    torch.ops.load_library(path)
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torch/_ops.py", line 220, in load_library
    ctypes.CDLL(path)
  File "/data/miniconda3/envs/py39/lib/python3.9/ctypes/__init__.py", line 382, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libcudart.so.11.0: cannot open shared object file: No such file or directory

错误原因

torch 的某个库与 torch 版本不兼容,上面的提示是 torchaudio 异常

错误排查

先执行:

pip list|grep torch

输出:

pytorch-lightning        1.7.6
torch                    1.11.0
torchaudio               0.13.0
torchmetrics             1.2.1
torchvision              0.12.0

一个一个的排除

$ python
import torchaudio
import torchmetrics
import torchmetrics

import torchaudio 得到错误:

  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/__init__.py", line 1, in 
    from torchaudio import (  # noqa: F401
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/_extension.py", line 135, in 
    _init_extension()
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/_extension.py", line 105, in _init_extension
    _load_lib("libtorchaudio")
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/_extension.py", line 52, in _load_lib
    torch.ops.load_library(path)
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torch/_ops.py", line 220, in load_library
    ctypes.CDLL(path)
  File "/data/miniconda3/envs/py39/lib/python3.9/ctypes/__init__.py", line 382, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libcudart.so.11.0: cannot open shared object file: No such file or directory

import pytorch_lightning 得到错误:

  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/__init__.py", line 1, in 
    from torchaudio import (  # noqa: F401
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/_extension.py", line 135, in 
    _init_extension()
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/_extension.py", line 105, in _init_extension
    _load_lib("libtorchaudio")
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torchaudio/_extension.py", line 52, in _load_lib
    torch.ops.load_library(path)
  File "/data/miniconda3/envs/py39/lib/python3.9/site-packages/torch/_ops.py", line 220, in load_library
    ctypes.CDLL(path)
  File "/data/miniconda3/envs/py39/lib/python3.9/ctypes/__init__.py", line 382, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libcudart.so.11.0: cannot open shared object file: No such file or directory

可知 torchaudio、pytorch_lightning、torchmetrics 这几个包与 torch 版本不兼容

torch                    1.11.0

对应版本:
pytorch_lightning        2.0
torchaudio               0.11.0
torchmetrics             0.11.1

解决方法

pip安装

pip install pytorch_lightning==2.0 torchaudio==0.11.0  torchmetrics==0.11.1    -i https://mirrors.aliyun.com/pypi/simple/

验证

python train.py

正常运行,完美解决!!

参考

https://github.com/pytorch/vision#installation
https://pytorch.org/audio/main/installation.html#compatibility-matrix
https://github.com/pytorch/text
https://pytorch.org/get-started/previous-versions/

你可能感兴趣的:(人工智能,深度学习,libcudart.so.11,torch)