pytorch 软件库9.0:无法打开共享目标文件:无此文件或目录

iecba09b  于 2023-01-02  发布在  其他
关注(0)|答案(5)|浏览(233)

我在Ubuntu 18.04下使用Pytorch,并尝试import torchvision,但我得到了一个错误libcudart.so.9.0: cannot open shared object file: No such file or directory
有人能帮忙修吗?谢谢。
以下信息是详细的错误日志:

Traceback (most recent call last):
  File "/home/x/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2882, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-6dd351122000>", line 1, in <module>
    import torchvision
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/__init__.py", line 1, in <module>
    from torchvision import models
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/models/__init__.py", line 11, in <module>
    from . import detection
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/models/detection/__init__.py", line 1, in <module>
    from .faster_rcnn import *
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/models/detection/faster_rcnn.py", line 7, in <module>
    from torchvision.ops import misc as misc_nn_ops
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/ops/__init__.py", line 1, in <module>
    from .boxes import nms, box_iou
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/ops/boxes.py", line 2, in <module>
    from torchvision import _C
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: libcudart.so.9.0: cannot open shared object file: No such file or directory
import torch
import torch.nn as nn
import torchvision.transforms as transforms
Traceback (most recent call last):
  File "/home/x/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2882, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-677acbcfae34>", line 1, in <module>
    import torchvision.transforms as transforms
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/__init__.py", line 1, in <module>
    from torchvision import models
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/models/__init__.py", line 11, in <module>
    from . import detection
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/models/detection/__init__.py", line 1, in <module>
    from .faster_rcnn import *
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/models/detection/faster_rcnn.py", line 7, in <module>
    from torchvision.ops import misc as misc_nn_ops
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/ops/__init__.py", line 1, in <module>
    from .boxes import nms, box_iou
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/x/.local/lib/python3.6/site-packages/torchvision/ops/boxes.py", line 2, in <module>
    from torchvision import _C
  File "/home/x/pycharm-2019.2/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: libcudart.so.9.0: cannot open shared object file: No such file or directory
yduiuuwa

yduiuuwa1#

如果您使用的是anaconda,下面的方法可以解决您的问题。

conda install -c anaconda cudatoolkit==9.0

您还可以尝试以下操作。
确保CUDA版本为9.0。并将以下2行添加到~/.bashrc

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

然后,运行:

source  ~/.bashrc

将以下行添加到/etc/ld.so.conf.d/cuda.conf

/usr/local/cuda/lib64

并运行:

sudo ldconfig
pw9qyyiw

pw9qyyiw2#

使用anaconda,torch版本为:

pytorch==1.1.0
torchvision==0.3.0
cudatoolkit=10.0

存在相同的问题,请通过将torchvision==0.3.0更改为torchvision==0.2.2来解决该问题

4jb9z9bj

4jb9z9bj3#

1.使用以下方法之一检查您的CUDA版本:

nvidia-smi
 nvcc -V

1.检查您的Pytorch CUDA版本,如下所示:

python
 import torch
 torch.version.cuda

1.版本应该匹配。否则,您需要升级/降级CUDA或对Pytorch执行相同操作。错误libcudart.so.9.0: cannot open shared object file: No such file or directory表示版本不匹配。您的Pytorch是CUDA 9.0,但CUDA是另一个版本。
1.要解决这个问题,请使用正确的CUDA版本安装Pytorch,如下所示:

conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch

注意:将Pytorch和CUDA Toolkit版本替换为所需版本。检查可用版本here
1.如果适用,重新构建Pytorch:

rm -rf build
 python setup.py develop
ilmyapht

ilmyapht4#

尝试以下命令

pip3 install torch===1.2.0 torchvision===0.4.0 -f https://download.pytorch.org/whl/torch_stable.html

我正在使用CUDA版本:11.6,这解决了我的错误。
Source: https://github.com/pytorch/pytorch/issues/25173#issuecomment-524802888

dgjrabp2

dgjrabp25#

下面是一个独立于cuda版本的通用解决方案。
1.目标是设置到cuda库(称为libcudart.so.<version number>)的正确路径。
1.我们通过sudo find / -name 'libcudart.so.<version number>'求出这条路径
1.我们必须在.bashrc中添加包含libcudart.so.<version number>的文件夹(而不是文件)的路径:
export LD_LIBRARY_PATH=<path to libcudart.so file>:$LD_LIBRARY_PATH

相关问题