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
    from fastai import *
    from import *

I get the following error:

ImportError: /usr/local/lib/python3.6/dist-packages/torchvision/ 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(), 
    cuda_output = !ldconfig -p|grep|sed -e 's/.*\.\([0-9]*\)\.\ 
    accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'

    !pip install torch_nightly -f{accelerator}/torch_nightly.html
    !pip install fastai

     import torch


And this is the full error message I get:

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

  ImportError: /usr/local/lib/python3.6/dist- 
  packages/torchvision/ 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.