Reputation: 10051
I'm using Pytorch under Ubuntu 18.04 and trying to import torchvision
, but I get an error libcudart.so.9.0: cannot open shared object file: No such file or directory
.
Someone could help to fix it? Thanks.
The infos below are detailed error logs:
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
Upvotes: 3
Views: 16625
Reputation: 7171
Here's a generic solution independent from the cuda version.
The goal to set the correct path to the cuda library which is called libcudart.so.<version number>
.
We find this path by sudo find / -name 'libcudart.so.<version number>'
We must add the path to the folder (not to the file) containing libcudart.so.<version number>
in the .bashrc :
export LD_LIBRARY_PATH=<path to libcudart.so file>:$LD_LIBRARY_PATH
Upvotes: -1
Reputation: 531
Try the following command
pip3 install torch===1.2.0 torchvision===0.4.0 -f https://download.pytorch.org/whl/torch_stable.html
I am using CUDA Version: 11.6 and this solved my error.
Source: https://github.com/pytorch/pytorch/issues/25173#issuecomment-524802888
Upvotes: -2
Reputation: 166
using anaconda
, torch version is:
pytorch==1.1.0
torchvision==0.3.0
cudatoolkit=10.0
has the same problem, and fix it by changing torchvision==0.3.0
to torchvision==0.2.2
Upvotes: 2
Reputation: 8032
Check your CUDA version with one of these:
nvidia-smi
nvcc -V
Check your Pytorch CUDA version like this:
python
import torch
torch.version.cuda
The versions should match. Otherwise you need to either upgrade/downgrade your CUDA or do the same but for Pytorch. The error libcudart.so.9.0: cannot open shared object file: No such file or directory
means that the versions don't match. You have Pytorch for CUDA 9.0, but your CUDA is another version.
To solve this install Pytorch with the correct CUDA version like this:
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch
NOTE: Replace the Pytorch and the CUDA Toolkit version with the desired ones. Check the available versions here.
If applicable, rebuild your Pytorch:
rm -rf build
python setup.py develop
Upvotes: 1
Reputation: 37741
If you are using anaconda
, the following may fix your problem.
conda install -c anaconda cudatoolkit==9.0
You can also try the followings.
Make sure the CUDA version is 9.0. And add the following 2 lines to ~/.bashrc
.
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Then, run:
source ~/.bashrc
Add the following lines to /etc/ld.so.conf.d/cuda.conf
/usr/local/cuda/lib64
And run:
sudo ldconfig
Upvotes: 10