How to fix the PyTorch installation that can't load the wrapped C libraries?

I’m working on google colab ( python 3.6 and GPU), I import torch (1.2.0) with no errors and I use the following to import fastai:

    import fastai
    print(fastai.__version__)
    from fastai import *
    from fastai.vision import *

I get the following error:

ImportError: /usr/local/lib/python3.6/dist-packages/torchvision/_C.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN3c106Device8validateEv

I have tried to install different torch versions like 1.0.0 and work with earlier python versions. I have also tried to install fastai and its dependencies manually using !pip , but nothing worked.

This is the complete code I used to install torch:

      from os.path import exists
      from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag

    platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), 
    get_abi_tag())
    cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*\.\([0-9]*\)\.\ 
    ([0-9]*\)$/cu\1\2/'
    accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'

    !pip install torch_nightly -f 
     https://download.pytorch.org/whl/nightly/{accelerator}/torch_nightly.html
    !pip install fastai

     import torch

     print(torch.__version__)
     print(torch.cuda.is_available())
     print(torch.backends.cudnn.enabled)

And this is the full error message I get:

    ImportError                                                           
    Traceback (most recent call last)
    <ipython-input-5-4b8b8d8134df> in <module>()
  2 print(fastai.__version__)
  3 from fastai import *
  ----> 4 from fastai.vision import *
    8 frames
  /usr/local/lib/python3.6/dist-packages/torchvision/ops/boxes.py in 
  <module>()
  1 import torch
  ---->  2 from torchvision import _C
  3 
  4 
  5 def nms(boxes, scores, iou_threshold):

  ImportError: /usr/local/lib/python3.6/dist- 
  packages/torchvision/_C.cpython-36m-x86_64-linux-gnu.so: undefined 
  symbol: _ZN3c106Device8validateEv  

I’m unable to use ImageDataBunch.from_folder because of the Pytorch installation error and the fastai import error. I get the error NameError: name 'ImageDataBunch is not defined when I do.

Note: I did use the same code before and I was able to use fastai and ImageDataBunch.from_folder with no import errors , but I’m guessing that an update to fastai or torch happened.

This is happening because the latest version of torchvision i.e., 0.3, has C++ ops that have been compiled with some version of cuda. Pull request #971 on torchvision fixes this. I would recommend installing torchvision from source. The instructions can be found on the torchvision github repo.