我在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
5条答案
按热度按时间yduiuuwa1#
如果您使用的是
anaconda
,下面的方法可以解决您的问题。您还可以尝试以下操作。
确保CUDA版本为9.0。并将以下2行添加到
~/.bashrc
。然后,运行:
将以下行添加到
/etc/ld.so.conf.d/cuda.conf
并运行:
pw9qyyiw2#
使用
anaconda
,torch版本为:存在相同的问题,请通过将
torchvision==0.3.0
更改为torchvision==0.2.2
来解决该问题4jb9z9bj3#
1.使用以下方法之一检查您的CUDA版本:
1.检查您的Pytorch 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,如下所示:
注意:将Pytorch和CUDA Toolkit版本替换为所需版本。检查可用版本here。
1.如果适用,重新构建Pytorch:
ilmyapht4#
尝试以下命令
我正在使用CUDA版本:11.6,这解决了我的错误。
Source: https://github.com/pytorch/pytorch/issues/25173#issuecomment-524802888
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