我在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
答案 0 :(得分:2)
如果您使用的是anaconda
,则以下方法可以解决您的问题。
conda install -c anaconda cudatoolkit==9.0
您也可以尝试以下方法。
确保CUDA版本为9.0。并将以下两行添加到~/.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
答案 1 :(得分:1)
使用anaconda
,割炬版本为:
pytorch==1.1.0
torchvision==0.3.0
cudatoolkit=10.0
具有相同的问题,并通过将torchvision==0.3.0
更改为torchvision==0.2.2
答案 2 :(得分:0)
使用以下一项检查您的CUDA版本:
nvidia-smi
nvcc -V
像这样检查您的Pytorch CUDA版本:
python
import torch
torch.version.cuda
版本应该匹配。否则,您需要升级/降级CUDA或执行相同的操作(仅适用于Pytorch)。错误libcudart.so.9.0: cannot open shared object file: No such file or directory
表示版本不匹配。您拥有适用于CUDA 9.0的Pytorch,但您的CUDA是另一个版本。
要解决此问题,请使用正确的CUDA版本安装Pytorch,如下所示:
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch
注意:用所需的版本替换Pytorch和CUDA Toolkit版本。检查可用的版本here。
如果适用,重建您的Pytorch:
rm -rf build
python setup.py develop