libcudart.so.9.0: cannot open shared object file: No such file or directory
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 "&lt;ipython-input-2-6dd351122000&gt;", line 1, in &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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 "&lt;ipython-input-4-677acbcfae34&gt;", line 1, in &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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 &lt;module&gt;
    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


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

